CRM 2011 Converted script not working RRS feed

  • Question

  • The script ran successfully in CRM 4.0 but after upgrading to CRM 2011 the script does not seem to work at all.  Below is the upgraded script. 

    Has some routines changed or are not available anylonger?  Can "Debugger;" be added to go to debug mode?

    It is flagged as enabled.   Is there some other settings needing to be set?


    function Form_onload()
    var xml = "" +
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
    GenerateAuthenticationHeader() +
    " <soap:Body>" +
    " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
    " <q1:EntityName>systemuser</q1:EntityName>" +
    " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
    " <q1:Attributes>" +
    " <q1:Attribute>businessunitid</q1:Attribute>" +
    " <q1:Attribute>firstname</q1:Attribute>" +
    " <q1:Attribute>fullname</q1:Attribute>" +
    " <q1:Attribute>lastname</q1:Attribute>" +
    " <q1:Attribute>organizationid</q1:Attribute>" +
    " <q1:Attribute>systemuserid</q1:Attribute>" +
    " </q1:Attributes>" +
    " </q1:ColumnSet>" +
    " <q1:Distinct>false</q1:Distinct>" +
    " <q1:Criteria>" +
    " <q1:FilterOperator>And</q1:FilterOperator>" +
    " <q1:Conditions>" +
    " <q1:Condition>" +
    " <q1:AttributeName>systemuserid</q1:AttributeName>" +
    " <q1:Operator>EqualUserId</q1:Operator>" +
    " </q1:Condition>" +
    " </q1:Conditions>" +
    " </q1:Criteria>" +
    " </query>" +
    " </RetrieveMultiple>" +
    " </soap:Body>" +
    "</soap:Envelope>" +

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);

    var resultXml = xmlHttpRequest.responseXML;
    var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");

    var firstNameNode = entityNode.selectSingleNode("q1:firstname");
    var lastNameNode = entityNode.selectSingleNode("q1:lastname");
    var fullNameNode = entityNode.selectSingleNode("q1:fullname");
    var systemUserIdNode = entityNode.selectSingleNode("q1:systemuserid");
    var businessUnitIdNode = entityNode.selectSingleNode("q1:businessunitid");
    var organizationIdNode = entityNode.selectSingleNode("q1:organizationid");

    // function to hide the email message field
    gHideField = function (name){
         var field = document.getElementById(name+'_d');
         var fieldcapt = document.getElementById(name+'_c');
         if(field != null){field.style.display='none';}
         if(fieldcapt != null){fieldcapt.style.display='none';}


    // Get the Regarding field
    var TheRegarding = new Array;
    TheRegarding = null;
    TheRegarding= crmForm.all.regardingobjectid.DataValue;

    // If the regarding field IS blank then check to see if this user should be able to see the message

    if (TheRegarding == null) {

       // Get the email From user id, if there is one.
        var lookUpFrom = new Array();
        lookUpFrom = crmForm.all.from.DataValue;
        var pFromId = lookUpFrom[0].id;

        sFlag = "Hide"   // Default to hide the field, unless we prove this user may see the Message field

      // If the "From" is also the Current User then allow them to see the Message field
       if(systemUserIdNode.text == pFromId) {

         sFlag = "Visible";

       }     // if(systemUserIdNode.text == pFromId) {

       // Ok the "From" is not the current user so lets loop through the "To" user id's to see if the Current User is one of the "To" people
       if (sFlag == "Hide") {

           var lookUpTo = new Array();
           lookUpTo = crmForm.all.to.DataValue;

           iMax = lookUpTo.length - 1;     // How many "To" addresses are there?
          for (i = 0; i<=iMax;i++) {

              var pToId = lookUpTo[i].id;         // Get "To" user id

              if(systemUserIdNode.text == pToId) {        // Compare "To" user Is to Current System User Id
                    sFlag = "Visible";                                     // This Current User Id matchs this "To" user is, let them see the Message field.

              }    // if(systemUserIdNode.text == pToId) {

          }  // For Next i loop

       }    //if (sFlag == "Hide") {

       if (sFlag == "Hide") {         // There was NO regarding field and the Current User Id is NOT the From or any of the To people, so hide the Message field

            gHideField ('Description');

       }   // if (sFlag == "Hide") {

    }   //if (TheRegarding == null) {

    Wednesday, April 13, 2011 5:55 PM


All replies

  • The syntax for jscript has changed greatly.  To understand the changes you might want to download the SDK.



    There is also a tool to convert your script the the 2011 syntax.




    Also, if you want to see how retrievemultiple calls work against the new 2011 organization service (in case you don't want to use the old legacy service) check these out.


    retrievemultiple calls in jscript - http://mileyja.blogspot.com/2011/03/crm-2011-retrievemultiple-calls-in.html


    Parsing responses from calls with DOM Parser - http://mileyja.blogspot.com/2011/03/microsoft-dynamics-crm-2011-parsing.html







    Jamie Miley
    Linked-In Profile
    Follow Me on Twitter!
    Wednesday, April 13, 2011 6:13 PM
  • Thank you for the information.  The script came through the CRM 4.0 to CRM 2011 conversion.  I also used the script convert tool and no changes were made.

    I am new to these scripts so I am not sure where to start.  It worked fine in 4.0 but does not now. 

    Is the use of debugger; in a script still work?  I am concern that other than setting the script to enabled there may be something else that needs to be set.


    Wednesday, April 13, 2011 7:09 PM
  • debugger; does work. 

    Out of curiosity, when you specify your function to run in the GUI event handler, make sure you don't include parenthesis in the function name.

    so if your main function in jscript you want to run is called runme(), make sure you specify runme when hooking it up and not runme()

    If you put the parenthesis in the form properties, event handler set up it will not work at all and debugger lines won't even be hit, I have been burned by this before.

    Jamie Miley
    Linked-In Profile
    Follow Me on Twitter!
    Thursday, April 14, 2011 5:46 PM
  • When you get to the point where the script is firing, your major issue with getting it to work in CRM 2011 will be the following:

    gHideField = function (name){ 
       var field = document.getElementById(name+'_d'); 
       var fieldcapt = document.getElementById(name+'_c'); 
       if(field != null){field.style.display='none';} 
       if(fieldcapt != null){fieldcapt.style.display='none';} 

    The DOM structure of a CRM Entity Instance form has changed quite a lot between CRM 4.0 and 2011.  The technique you've used to show/hide fields searches for specific elements by their "id".  Those elements and their layout are no longer the same.

    Only supported customisations will survive the upgrade process and "hacking" the DOM of the form is not supported.  We have all done it... but it's not supported.

    Hence, the new built-in mechanisms in CRM 2011 to show/hide elements (the Xrm.Page.ui namespace):


    For example, to hide a control, you can now (in a supported manner) execute the following:


    To hide the section in which the control is contained:


    --pogo (pat)
    Thursday, April 14, 2011 11:57 PM
  • Tuesday, February 14, 2012 4:43 PM