Pass Parameters to Quick Create Form in Dynamics 365 using formContext.data.attributes
With the deprecation of Xrm.Page.context.getQueryStringParameters, Microsoft Docs article suggested using formContext.data.attributes API to make retrieval of non-entity bound data consistent across entity forms.
But some of the sample codes that I found online are all using the deprecated Xrm.Page.context.getQueryStringParameters and some are using undocumented Xrm.Utility.getGlobalContext().getQueryStringParameters(). I found some forum thread saying that "getQueryStringParameters" itself is deprecated regardless of whether is from Xrm.Page or Xrm.Utility.
So here is a sample code on how to pass parameters to another form. In this example, I am trying to pass the custom parameter from the main form of an entity to the quick create form which is opened by Xrm.Navigation.openForm API.
First of all, you will need to add the parameter in the Form Properties of the form that you are receiving the parameter (Quick Create form in this case). Follow this Microsoft Docs article to set the name of the parameter
Note: If the parameter is not working on someone else's machine, you might want to add the parameter in the main form as well according to Daryl LaBar.
This is the sample code on my Main form where I am passing the parameter lzw_test_parameter and open the Quick Create a form using Xrm.Navigation.openForm
This is the sample code on my Quick Create form where I am getting the parameter passed by the other form
But some of the sample codes that I found online are all using the deprecated Xrm.Page.context.getQueryStringParameters and some are using undocumented Xrm.Utility.getGlobalContext().getQueryStringParameters(). I found some forum thread saying that "getQueryStringParameters" itself is deprecated regardless of whether is from Xrm.Page or Xrm.Utility.
So here is a sample code on how to pass parameters to another form. In this example, I am trying to pass the custom parameter from the main form of an entity to the quick create form which is opened by Xrm.Navigation.openForm API.
First of all, you will need to add the parameter in the Form Properties of the form that you are receiving the parameter (Quick Create form in this case). Follow this Microsoft Docs article to set the name of the parameter
Note: If the parameter is not working on someone else's machine, you might want to add the parameter in the main form as well according to Daryl LaBar.
This is the sample code on my Main form where I am passing the parameter lzw_test_parameter and open the Quick Create a form using Xrm.Navigation.openForm
var entityFormOptions = {};
entityFormOptions["entityName"] = "contact";
entityFormOptions["useQuickCreateForm"] = true;
var formParameters = {};
formParameters["lzw_test_parameter"] = "Test parameter value"; // Custom Parameter
Xrm.Navigation.openForm(entityFormOptions, formParameters);
This is the sample code on my Quick Create form where I am getting the parameter passed by the other form
if (formContext.data.attributes.get("lzw_test_parameter") !== null) // sample code for getting non-entity bound data
{
Xrm.Navigation.openAlertDialog({ text: formContext.data.attributes.get("lzw_test_parameter").getValue() }); // This will show the alert "Test parameter value"
}
Hi, Linn
ReplyDeleteThanks for your sharing. I'm also facing this now. Could you please help tell me how to change below?
・ if( Xrm.Page.context.getQueryStringParameters().parentLookupControlId == "new_shipto_name")
・ var createFromId = Xrm.Page.context.getQueryStringParameters()._CreateFromId;
Hi
DeleteThanks for reading my blog post.
Passing parameter will only work if you are opening the quick create form using Xrm.Navigation.openForm
In your scenario, I believe the script is detecting the source lookup attribute and the record ID when the user open the quick create form from the + Add new record option of the lookup.
For that issue, I don't have any supported solution at the moment.
Please just try to replace Xrm.Page.context.getQueryStringParameters() with Xrm.Utility.getGlobalContext().getQueryStringParameters() and see if it works.
Hi Linn, tihs is not working, I getting null when using formContext.data.attributes.get("name").getValue().\
ReplyDeleteAny suggestion that pls.
1. Did you define the Form Parameter as in the screenshot below?
Deletehttps://1.bp.blogspot.com/-WGUhSqT-C6Q/Xb6xceqIWuI/AAAAAAAA5oA/heHLncL7Qg0TbwA7WtdMltfUMyItP2K8wCLcBGAsYHQ/s1600/Form%2BProperties%2BParameter.png
2. Did you also pass the formParameters for the form script which opens the quick create form?
formParameters["name"] = "NameValue"; // Custom Parameter
Xrm.Navigation.openForm(entityFormOptions, formParameters);
Read it three times and tried it but it is saying my parameter "isMasterView" is not defined.
ReplyDelete