Skip to main content
Dynamics 365 general forum
Suggested answer

Help on return a value from Xrm.Internal.openDialog

editSubscribe (0) ShareShare
Posted on by 5

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;
            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); });
    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;

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?


  • Burg0 Profile Picture
    Burg0 5 on at
    RE: Help on return a value from Xrm.Internal.openDialog

    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.


  • Suggested answer
    Sayen Zhang Profile Picture
    Sayen Zhang on at
    RE: Help on return a value from Xrm.Internal.openDialog

    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 (

    Best Regards,

    Sayen Zhang

  • Burg0 Profile Picture
    Burg0 5 on at
    RE: Help on return a value from Xrm.Internal.openDialog

    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.

  • Suggested answer
    RE: Help on return a value from Xrm.Internal.openDialog


    I believe that

    function (returnValue) { alert(returnValue); } 

    is a callback, so the rest of your code should be there.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…


Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,068 Super User

Martin Dráb Profile Picture

Martin Dráb 222,591 Super User

nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans