Monday, 12 September 2016

Open Specific Form Using javascript in Dynamics CRM

Open Specific Form of any entity Using javascript in Dynamics CRM


In this post we'll learn how we can open a specific type of form of an entity using javascript.

Scenario: Let's say you have 2 different main form of phone call entity. You want to open specific form on the basis of specific attribute on the form. 

Here in this case we have a Call Type option set. On the basis of which use wants to open different form. For instance vales of Call Type may be Sales/Service and user wants to open new form of sales of phone call when he selects sales in option set and want to open main form of service of phone call if he selects service, he can implement the same using javascript as below:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  function ChoosePage()
{
var CallType = Xrm.Page.getAttribute("new_calltype").getValue();
if(CallType!=null)
{
   var FormId;
if (CallType==1) //Sales
{
FormId='78958D5A-FE73-45E8-8F78-950B1389BE2E';
}
else if (CallType==2) //Service
{
   FormId='A91390A5-99BB-4D10-9EEE-3A5C87F841F1';  
var parameters = {};
parameters["formid"] = FormId;
parameters["new_calltype"] = CallType;
Xrm.Utility.openEntityForm("phonecall", null, parameters);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here "null" signify that we are opening a new form.

If you want to open existing record in different form then you can pass Guid of that record.

* We can pass as many objects in parameter as we want which will come pre-set in the new form opened.

* The formid used in the code can be found in Customization->Entity->Forms

Hope it's helpful.


Suggestions and comments are highly appreciated.

Happy CRM...!