locked
what's wrong with my code? RRS feed

  • Question

  • I want to set "Party details" field visibility through "Initiating party" lookup field. I got error says "0.name is null or not an object". Here is my code:
    function setFieldVisibility() {
    
    
    
     var initiatingparty = Xrm.Page.getAttribute(INITIATING_PARTY_FIELD).getValue();
    
    
    
     if (initiatingparty != null && (initiatingparty[0].name == "Employer" || initiatingparty[0].name =="Other")) {
    
    
    
     Xrm.Page.getControl(PARTY_DETAILS_FIELD).setVisible(true);
    
    
    
     }
    
    
    
     else {
    
    
    
     Xrm.Page.getControl(PARTY_DETAILS_FIELD).setVisible(false);
    
    
    
     }
    
    
    
    }
    
    
    
    
    
    
    
    function new_initiatingpartyOnChange() {
    
    
    
     setFieldVisibility();
    
    
    
    }
    
    
    
    
    Thanks!


    • Edited by howexg9 Tuesday, July 26, 2011 8:30 PM
    Tuesday, July 26, 2011 8:24 PM

Answers

  • It looks to me that your "Initiating party" field should be a picklist, otherwise, it won't return a value of 0 when getValue method is called.

    In this case, you should change your code to

     var initiatingparty = Xrm.Page.getAttribute(INITIATING_PARTY_FIELD).getText();
     if (initiatingparty != null && (initiatingparty == "Employer" || initiatingparty =="Other")) {
     // ....
     }
    

    Daniel Cai | http://danielcai.blogspot.com
    • Marked as answer by howexg9 Tuesday, July 26, 2011 9:17 PM
    Tuesday, July 26, 2011 8:51 PM