Tudor Hofnar
Tudor Hofnar

Reputation: 267

How to change default form based on dropdown JS and CRM?

Ok so what I am trying to do in CRM 2011 is to have a dropdown menu where it has two options: "Support" and "Prof. Services", this is for the Case entity. Now, I have two forms one named "Support" and one name "Prof. Services".

What I want to happen is that if a Case has the dropdown set to "Support" when it is opened it should open with the "Support" form and if the dropdown is set to "Prof. Services" it should open with the "Prof. Services" form.

I came across this article: http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/5ba919f7-9f7c-4abf-ba88-224951bb7c11 and used that code in a JScript web resource. Then on both of my forms I went to the Form Properties and added an OnLoad function setForm() (as in my JS code below). But this doesn't work. The right form is not showing for the right case/dropdown value. This is the code I am using: (any help debugging this would be much appreciated) *keep in mind I am beginner JS'er :)

function setForm() {
var currentForm= Xrm.Page.ui.formSelector.getCurrentItem().getId();                         
var Information;
var cType = Xrm.Page.data.entity.attributes.get('new_CaseType').getText().toLowerCase();    
var forms = Xrm.Page.ui.formSelector.items.get();
var i = 0;

for (i = 0; i < forms.length; i++) {                            
    if (forms[i].getLabel().toLowerCase()==cType) {             
        if (currentForm!=forms[i].getId()) {                    
            forms[i].navigate();
        }
        return;
    }
    if (forms[i].getLabel().toLowerCase()=='information') {     
        Information=forms[i];                                   
    }
}
if (currentForm!=Information.getId()) {                         
    Information.navigate();
}
}

Upvotes: 2

Views: 4005

Answers (1)

James Wood
James Wood

Reputation: 17562

For help with debugging I would suggest having a read of these fine articles:

  1. How to Debug JScript in Microsoft Dynamics CRM 2011.
  2. Debugging Script with the Developer Tools.
  3. How-to series: Easily debug your CRM JavaScript code in IE8.

Upvotes: 1

Related Questions