locked
CRM 2011 - JavaScript... global variables... sort of. RRS feed

  • Question

  • I've notice that in the CRM form customizations the JavaScript never users a varible to hold the name of the field.  Maybe something like...

    var firstnameField = "firstname";
    var middlenameField = "middlename";
    var lastnameField = "lastname";
    
    function....
    {
         Xrm.Page.getAttribute(firstnameFiled).getvalue();
    }
    
    function....
    {
         Xrm.Page.getAttribute(firstnameFiled).getvalue();
    }
    
    function....
    {
         Xrm.Page.getAttribute(firstnameFiled).getvalue();
    }
    

    Why is this?  Can we just use a a closure to get this to work as expected?  I have hundreds of lines of JavaScript code that deals with this sort of thing and it really sucks to have to go back through it and rename a field in dozens of places.  I figure there must be a reason for not doing this.  I have noticed that on some of the SDK functions using a string works and others it does not.  Does anyone know what that is?

    Any thoughts about how to best deal with this?  I have set it up using a closure and it works fine, but later I removed it in fear of something I don't know about. 


    Jon Gregory Rothlander


    Monday, April 7, 2014 3:54 PM

All replies