Xrm.Navigation.openForm – A function which has been used by almost every consultant to open a entity record whether existing or new record.
This is a function which as a developer and Dynamics consultant, I believe is one of the most under utilized function. This function have so many parameters which are not widely used or I shall say unknown to many of us who have been working in Dynamics 365 for quite sometime. And one of them is the ability to open a record with a particular Business process flow, business process flow instance and even a selected stage of the Business process flow instance.
Below is the nomenclature of Xrm.Navigation.openForm
Xrm.Navigation.openForm(entityFormOptions,formParameters).then(successCallback,errorCallback);
The important parameter here is entityFormOptions. We may have used entityFormOptions to pass field values, record and entity name. Entity form options allow you set the Business process flow as well for the record.
var formOptions = {}; formOptions["processId"] =”<process flow id>”;
Once the record is opened, the record will load with the process flow id as mentioned in the code above.
There is another parameter which allows you to set the value of the process instance record as well. As record in Dynamics 365 can be in multiple process flows and you can switch between the process flow instances by setting both process id and process instance id. Below is the code to do the same.
var formOptions = {}; formOptions["processId"] =”<process flow id>”; formOptions[“processInstanceId”] = “<process instance id>”;
Well it’s still not over. With all the above code, the record shall load with the first stage of the whatever process has been applied. However many a times you shall need to switch the Business process flow of the record and load the record in a specific stage rather than the default first stage. In that case you can use another parameter which is “selectedStageId”.
Below is the sample code
var formOptions = {}; formOptions[“processInstanceId”] = “<process instance id>”; formOptions["processId"] =”<process flow id>”; formOptions[“selectedStageId”] = “<Id of the selected stage in Business process instance>”
This is a very common requirement which I face usually in customer requirements and hence thought of sharing the same.
Debajit Dutta
(Dynamics MVP)
For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com
Our product offerings:
Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)
CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)
Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.