4

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:

enter image description here

Can you help me?

Thanks. ``

jasonscript
  • 6,039
  • 3
  • 28
  • 43
Burg0
  • 41
  • 1
  • Never used it, but this function is named `Xrm.Internal.openDialog` for a reason: it is not a public (documented and supported) API and solutions based on it are almost guaranteed to break when migrated to v9. – Henk van Boeijen May 03 '23 at 20:37
  • Hi Henk, have you some examples that i can use for my needs? Thanks – Burg0 May 08 '23 at 14:23

1 Answers1

0

UPDATE:

Hi all,

i've tried with another webresource directly in the same page that provides the calendars list and the selected value goes in another field, then the webresources goes hide, but the UI is not the best.

So, is there a way to return a selected value from a popUp in dynamics CRM 2016 (eventually in javascript) ?

Thanks.

Burg0
  • 41
  • 1