Requirement:
We would like to open and pass input parameters to an HTML web-resource in CRM Modal Dialog box after user clicks on a custom ribbon button on the entity Form. HTML web-resource will, in turn, call external URL using form “post” method. External URL will fetch data using input parameters and display the result in CRM Modal dialog box.
Problem Statement:
We are not able to pass input parameters to html web-resource from entity form.
*This post is locked for comments
Thanks Mark , It is a perfect solution.
Nitinsha
You can easily open a dialog with the following code
var currentRecId = window.parent.Xrm.Page.data.entity.getId(); var someText = "info"; var addParams = "recordid=" + currentRecId + "&sometext=" + someText; //Build the URI var src = "/webresources/new_customDialog.htm?Data=" + encodeURIComponent(addParams); //Build dialog options var DialogOptions = new Xrm.DialogOptions(); DialogOptions.width = 1300; DialogOptions.height = 850; Xrm.Internal.openDialog(src, DialogOptions, null, null, CallbackFunction); //Execute some action on closing of dialog function CallbackFunction(returnValue) { //Do something with the returned value }
Then within the dialog you can use the following function to get the parameters.
function ParseQueryString(query) { var result = {}; if (typeof query == "undefined" || query == null) { return result; } var queryparts = query.split("&"); for (var i = 0; i < queryparts.length; i++) { var params = queryparts[i].split("="); result[params[0]] = params.length > 1 ? params[1] : null; } return result; }
Then to get the parameters use the function as such
//Get the parameters passed var passedparams = ParseQueryString(GetGlobalContext().getQueryStringParameters()["Data"]); //Populate the property ID var currentRecId = passedparams.recordid; var someText= passedparams.sometext;
One thing to note, you will run into cross domain issues if you are obtaining data from a seperate domain. Take a look at this thread it may be of use to you https://community.dynamics.com/crm/f/117/t/137165.aspx. I have used Actions to owvercome this and it works well.
Hope this helps
Mark
Are you calling any javascript function to open modal dialogue? if so you can easily pass record values as query string parameter to the Dialogue window.
find below sample code to pass multiple values
var customParameters = encodeURIComponent("first=First Value&second=Second Value&third=Third Value");
Xrm.Utility.openWebResource("new_webResource.htm",customParameters);
detailed information on passing multiple values to web resouce can be found here
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,817
Most Valuable Professional
nmaenpaa
101,156