When I check on the official documentation about Xrm.Navigation.openForm, I am interested in attribute formParameters. Where in the docs, stated that we can pass custom value from caller to the form that we want to open. The scenario of it is let’s say we want to open dialog (from custom web resource) or something that temporary (not depend on field value). But when I trying it, I can’t make it work on the UCI app.

Before we go to the implementation code. The requirement of it is to set the custom parameter first (to avoid error). Here is the parameter that I setup (from Form > Form Properties > Parameters):

Here is the code for opening a custom entity and pass the custom parameters:
var form = {
'entityName': 'new_orderdetail'
};
var formParameters = {
'Message_': 'hello world!'
};
Xrm.Navigation.openForm(form, formParameters)
When the code is successfully executed, the form reloads but if we inspect the query string, it will show you nothing:

Then I try to find is there any documentation to get custom query string parameters in the Client Scripting area. But I found none of them except an article from Inogic that you can find here. Using the code snippets from the article which gets query string value from the browser, I already predict it will not work either because CRM did not pass anything in the query string after we invoke the Xrm.Navigation.openForm even we already pass the form parameters.
Solution To Pass Custom Value
The solution that I can think of is using either localStorage / sessionStorage. As long as we can dispose of the object after we use it. It will be okay. So the code in the above (because of the form parameter not working), I change to this:
var form = {
'entityName': 'new_orderdetail'
};
// Or localStorage
sessionStorage.setItem('message', 'hello world!');
Xrm.Navigation.openForm(form);
Then don’t forget to delete it with sessionStorage/localStorage.removeItem after we use it on the Target form onLoad event:
function formOnLoad(context) {
...
if(sessionStorage.getItem('message')){
// Do your business logic
sessionStorage.removeItem('message');
}
...
}
The other solution is to using attribute value. Because by default we still can pass attribute value. Then on the form onLoad event, instead of we rely on the query string, we rely on the new_orderdetail attribute in this example:
var form = {
'entityName': 'new_orderdetail'
};
var formParameters = {
'new_orderdetail': 'New Record'
};
Xrm.Navigation.openForm(form, formParameters);
Here is the original result after you execute above code:

Then on the formOnLoad event you can change the value of that field to another and do whatever you want to do:
function formOnLoad(context) {
var formContext = context.getFormContext();
...
if(context.getAttribute('new_orderdetail').getValue() === 'New Record'){
context.getAttribute('new_orderdetail').setValue('helo world');
// Do your business logic
}
...
}
What you think?
2 thoughts on “Dynamics CRM Client Scripting: Passing Custom Value when using Xrm.Navigation.openForm”