Wednesday, December 17, 2014

Navigating to respective form dynamically in MultiFrom in MS CRM 2011 , MS CRM 2013

Hi All,

if we have multiple forms in an entity and we need to load the respective form to the user on basis of some flags in the , definitely can do as follows....
my scenario I am giving here is, suppose I have 3 forms (I am doing on case form) and the field I am taking is Case Origin (values are Phone, Email and Web)
1. Information ( if case origin is Web)
2. Phone Call (if case origin is Phone)
3. Email (if case origin is Email)

here is the code, just use this on load of each forms, I repeat it , use this on load of each 3 forms....
(WHY? cause each form has its own form properties and onLoad event to trigger).
let me give some back ground of the methods used here....
formSelector : used to get the list forms that are in the entity (only if more than 1)
getCurrentItem() : returns the current form rendered to the user (this is most important)
navigate() : it will help(force) to navigate to the form that's selecting

function _onLoad(){
if(Xrm.Page.ui.getFormType() == "2") //doing only on update mode, so only will get the Case Origin
{
                var caseOrigin = Xrm.Page.getAttribute('caseorigincode').getValue();
                var items = Xrm.Page.ui.formSelector.items.get();
                var currentItem = Xrm.Page.ui.formSelector.getCurrentItem();
                for (var it in items) //iterate all the items means forms
                {
                                 var form= items[it];
                                 var formLabel = form.getLabel(); //get the form label like Email, Phone Call
                                //Check condition Label from Form and the corresponding Case Origin and mainly if its not the Current Selected Form
                                 if (formLabel == "Phone Call" && caseOrigin == "1" && currentItem.getLabel() != "Phone Call")
                                 {
                                                 form.navigate(); //now in this case just navigate
 
                                 }
                                 else if (formLabel == "Email" && caseOrigin == "2" && currentItem.getLabel() != "Email")
                                 {
                                                 form.navigate();
                                 }
                                 else if (formLabel == "Information" && caseOrigin == "3" && currentItem.getLabel() != "Information")
                                 {
                                                 form.navigate();
                                 }
                }
 }
}

 you will get a flickering on the form, as it will reload again and we are navigating it to respective form. means if your default form or earlier the user was in Information form and now the case origin is Phone. so 1st OTB the Information form will be loaded and as per the above JS, it will check that the Case Origin is Phone, so it will navigate to Phone Call form and it will load for the user.
wahhh....
Hope this will help a lot guys....
 
Regards,
Yes.Sudhanshu

No comments:

Post a Comment