I'm using a 2016 on-premise dynamics crm and I want to open a popUp, select a value from a list and return it to the caller.
I can't use navigateTo and the only function that can return a value seems to be the (deprecated) openDialog.
I created 2 html web resources, one with a button that opens the second one.
The problem is that when the openDialog is hit, the page doesn't wait for the return value and fire the debugger right after it.
Here is the code of the first page:
function Click() {
var Entity = "calendar";
var Select = "?$select=name";
var Filter = "&$filter=type eq 1";
var addParams;
window.parent.Xrm.WebApi.retrieveMultipleRecords(Entity, Select + Filter).then(
function success(result) {
if (result != null && result.entities != null) {
for (var i = 0; i < result.entities.length; i++) {
if (i == 0)
addParams= "Param="+result.entities[i].name;
else
addParams+= "&Param="+result.entities[i].name;
}
var DialogOption = new window.parent.Xrm.DialogOptions;
DialogOption.width = 400; DialogOption.height = 400;
var webresourceurl = "/WebResources/calendarPage?Data=" + encodeURIComponent(addParams);
window.parent.Xrm.Internal.openDialog(
webresourceurl,
DialogOption,
null,
null,
function (returnValue) { alert(returnValue); }
);
debugger;
}
},
function (error) {
alert("error" + error.message);
}
);
}
Here is the code of the second page:
function getValue() {
var ele = document.getElementsByTagName('input');
var returnValue;
for (i = 0; i < ele.length; i++) {
if (ele[i].type == 'radio') {
if (ele[i].checked) {
alert(' Valore: ' + ele[i].value);
sessionStorage.setItem('name', ele[i].value);
returnValue = ele[i].value;
}
}
}
window.parent.Mscrm.Utilities.setReturnValue(returnValue);
closeWindow(true);
}
something like that:
Can you help me?
Thanks. ``