Hi everyone,
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.
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:
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.
Can you help me?
Thanks.
Hi partner,
i've tried but nothing happens.
Have you got some examples about how to do what i need?
How can i return a selected value from a popUp in dynamics crm 2016 (eventually using only javascript) ?
I've tried to insert another webresource in the same page that provide directly the calendars list and goes hide after save, filling a specified field, but the UI is not the best.
Thanks.
Hi partner,
Use Mscrm.Utilities.setReturnValue(returnValue) may work for sometime but will fail in future updates. I would suggest you update your code with the supported methods.
Hope this link will help you: Mscrm.Utilities.setReturnValue() discrepancy in UCI and legacy application - Unified Interface Forum Community Forum (dynamics.com)
Best Regards,
Sayen Zhang
Hi Xavier,
thanks for the reply.
It's a callback, but there is not other code below that, only the debugger line that u see.
And that alert is not hit by nothing.
Hi,
I believe that
function (returnValue) { alert(returnValue); }
is a callback, so the rest of your code should be there.
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156