locked
Javascript syntax error in CRM 2011 RU15 RRS feed

  • Question

  • The following javascript worked fine prior to RU15. Any idea on why I would be getting a syntax error now. This is simply setting some check boxes as true if the corresponding currancy field is filled in.

    function checkContractServiceFees_onLoad() {
       var rdsFee = Xrm.Page.getAttribute("nhs_rdsfee").getValue();
       var brokerFee = Xrm.Page.getAttribute ("new_brokerconsultantfee").getValue();
       var tpaFee = Xrm.Page.getAttribute("new_tpacommissionfee").getValue();
       var sterlingFee = Xrm.Page.getAttribute("new_sterlingfee").getValue();
       var otherFee = Xrm.Page.getAttribute("new_otherfee").getValue();
       var memberMaterialFee = Xrm.Page.getAttribute("nhs_membermaterialscost").getValue();
     if (rdsFee != null) {Xrm.Page.getAttribute("nhs_hasrdsfee").setValue(true)};
       else {Xrm.Page.getAttribute("nhs_hasrdsfee").setValue(false)};
     if (brokerFee !=null) {Xrm.Page.getAttribute("nhs_hasbrokerconsultantfee").setValue(true)};
       else {Xrm.Page.getAttribute("nhs_hasbrokerconsultantfee").setValue(false)};
     if (tpaFee !=null) {Xrm.Page.getAttribute("nhs_hastpafee").setValue(true)};
       else {Xrm.Page.getAttribute("nhs_hastpafee").setValue(false)};
     if (sterlingFee != null) {Xrm.Page.getAttribute("nhs_hassterlingfee").setValue(true)};
       else {Xrm.Page.getAttribute("nhs_hassterlingfee").setValue(false)};
     if (otherFee !=null) {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(true)};
      else {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(false)};
     if (memberMaterialFee !=null) {Xrm.Page.getAttribute("nhs_membermaterialsfee").setValue(true)};
     else {Xrm.Page.getAttribute("nhs_membermaterialsfee").setValue(false)};
    }
    Any assistance would be greatly appreciated.
    Tuesday, February 11, 2014 6:26 PM

Answers

  • Hi Jennifer,

    I suspect that the syntax error is coming from somewhere else in your scripts. Can you press F12 and find the line that the error is occurring on.

    Hope this helps,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, February 11, 2014 7:38 PM
    Answerer
  • Hi,
    I didn't test it but maybe the cause is the semicolon after the brace (and not inside), so instead of writing

    if (otherFee !=null) {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(true)};
      else {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(false)};

    try with

    if (otherFee !=null) {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(true);}
      else {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(false);}

    also to the other 5 if conditions.
    If I can give a suggestion I will rewrite your code in a different way:

    function setBooleanField(fieldToCheck, fieldToSet) {
       var fieldValue = Xrm.Page.getAttribute(fieldToCheck).getValue();
       var boolValue = false;
       if (fieldValue != null) { boolValue = true; }
       Xrm.Page.getAttribute(fieldToSet).setValue(boolValue);
    }
    
    function checkContractServiceFees_onLoad() {
       setBooleanField("nhs_rdsfee","nhs_hasrdsfee");
       setBooleanField("new_brokerconsultantfee","nhs_hasbrokerconsultantfee");
       setBooleanField("new_tpacommissionfee","nhs_hastpafee");
       setBooleanField("new_sterlingfee","nhs_hassterlingfee");
       setBooleanField("new_otherfee","nhs_hasotherfee");
       setBooleanField("nhs_membermaterialscost","nhs_membermaterialsfee");
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by JenniferNHS Wednesday, February 12, 2014 2:50 PM
    Tuesday, February 11, 2014 11:00 PM

All replies

  • Hi Jennifer,

    I suspect that the syntax error is coming from somewhere else in your scripts. Can you press F12 and find the line that the error is occurring on.

    Hope this helps,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, February 11, 2014 7:38 PM
    Answerer
  • Hi,
    I didn't test it but maybe the cause is the semicolon after the brace (and not inside), so instead of writing

    if (otherFee !=null) {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(true)};
      else {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(false)};

    try with

    if (otherFee !=null) {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(true);}
      else {Xrm.Page.getAttribute("nhs_hasotherfee").setValue(false);}

    also to the other 5 if conditions.
    If I can give a suggestion I will rewrite your code in a different way:

    function setBooleanField(fieldToCheck, fieldToSet) {
       var fieldValue = Xrm.Page.getAttribute(fieldToCheck).getValue();
       var boolValue = false;
       if (fieldValue != null) { boolValue = true; }
       Xrm.Page.getAttribute(fieldToSet).setValue(boolValue);
    }
    
    function checkContractServiceFees_onLoad() {
       setBooleanField("nhs_rdsfee","nhs_hasrdsfee");
       setBooleanField("new_brokerconsultantfee","nhs_hasbrokerconsultantfee");
       setBooleanField("new_tpacommissionfee","nhs_hastpafee");
       setBooleanField("new_sterlingfee","nhs_hassterlingfee");
       setBooleanField("new_otherfee","nhs_hasotherfee");
       setBooleanField("nhs_membermaterialscost","nhs_membermaterialsfee");
    }


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by JenniferNHS Wednesday, February 12, 2014 2:50 PM
    Tuesday, February 11, 2014 11:00 PM
  • I belive you are correct. I turned off the javascript on this form and tried to use the IE developer tools. I get the same error at line 8. We upgraded from RU12 to RU15 where we started seeing this error.

    SCRIPT1002: Syntax error
    edit.aspx?_CreateFromId=%7bA6353B5E-F293-E311-80A1-0050568C000E%7d&_CreateFromType=1010&etc=10024&pagemode=iframe&preloadcache=1392215522506, line 8 character 4

    Wednesday, February 12, 2014 2:45 PM
  • Thank you Guido. I always welcome assistance on my code. I am a beginner to javascript and really appreciate you taking the time to assist. I used your new code and it worked like a charm. Thanks much!!
    • Edited by JenniferNHS Wednesday, February 12, 2014 2:50 PM update
    Wednesday, February 12, 2014 2:46 PM