Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Help on return a value from Xrm.Internal.openDialog

(0) ShareShare
ReportReport
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;
          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:

pastedimage1683121389702v1.png

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.

  • 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.

    Thanks.

  • 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 (dynamics.com)

    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
    XM-22040801-0 Profile Picture
    XM-22040801-0 11 on at
    RE: Help on return a value from Xrm.Internal.openDialog

    Hi,

    I believe that

    function (returnValue) { alert(returnValue); } 

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans