web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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.

I have the same question (0)
  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at

    Hi,

    I believe that

    function (returnValue) { alert(returnValue); } 

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

  • Burg0 Profile Picture
    5 on at

    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
    Sayen Zhang Profile Picture
    on at

    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
    5 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 41

#2
Martin Dráb Profile Picture

Martin Dráb 38 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans