Friday, 1 November 2013

Java Script to Navigate to differrent form based on option set in a form MSCRM

Secanrio :When user select option set the layout of form should be different then on selecting different option set.
step 1: create one form new form , then we will have two forms Account and New Form
step 2: create a option set with two option set
form1 and form2
step3: wrtie a java script on form load and form save :

// JScript source code
function showForm() {
   
//get the form type
    if (Xrm.Page.ui.getFormType() == 2)

        var labelOfForm;

// get the option set value
    var Type = Xrm.Page.getAttribute("new_formtype").getValue();

    switch (Type) {
        case 100000000:
            labelOfForm = "Account";
            break;
        case 100000001:
            labelOfForm = "New Form";
            break;
        default:
            labelOfForm = "Account";
    }
// get the form label
    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != labelOfForm)
    {
        var items = Xrm.Page.ui.formSelector.items.get();
        for (var i in items) {
            var item = items[i];
            var itemId = item.getId();
            var itemLabel = item.getLabel()
//if current form label is different then it will navigate to different form
            if (itemLabel == labelOfForm) {

                item.navigate();


            }
        }
    }
}


No comments:

Post a Comment