locked
Make All Read Only Fields Available RRS feed

  • Question

  • We've written jscript web resource to disable all fields but 2.  This is part of an approval process, and the jscript works.  Once the approver indicates approval with changes (selected from an option set), we tried to write another function to re-enable the fields, but the code is not doing anything.  I am not real familiar with controls.  Here are the scripts:

    //MakeFieldsReadOnly, this works fine.
    function AllReadOnly_onchange()
    {
    var RequestApproval = Xrm.Page.getAttribute("synact_requestapproval");
    var ApprovalStatus = Xrm.Page.ui.controls.get("synact_approvalstatus");
    var ApprovalDate = Xrm.Page.ui.controls.get("synact_approvaldate");
    var controls = Xrm.Page.ui.controls.get();
    for (var i in controls)
       {
          var control = controls[i];
    if (!control.getDisabled() && RequestApproval.getValue() == 1)
          {
          control.setDisabled(true);
          ApprovalStatus.setDisabled(false);
          ApprovalDate.setDisabled(false);

          }
       }
    }

    //Make All Fields Available, nothing happens.

    function ApprovalStatus_onchange()
    {
    var ApprovalStatus = Xrm.Page.getAttribute("synact_approvalstatus").getValue();
    var controls = Xrm.Page.ui.controls.get();
    for (var i in controls)
       {
          var control = controls[i];
    if(!control.getDisabled() && (ApprovalStatus == 100000001 || ApprovalStatus == 100000002))
       {  
          control.setDisabled(false);
       }
    }
    }


    Ken Compter

    Wednesday, July 17, 2013 7:34 PM

Answers

  • I forgot this line inside AllReadOnly_onchange and ApprovalStatus_onchange functions

    var controls = Xrm.Page.ui.controls.get();

    I fixed the before post.


    My blog: www.crmanswers.net



    • Edited by Guido PreiteMVP Wednesday, July 17, 2013 8:56 PM fixed
    • Marked as answer by kcompter Thursday, July 18, 2013 1:19 PM
    Wednesday, July 17, 2013 8:53 PM

All replies

  • Hi,
    I think the problem is with this line

    if(!control.getDisabled() && (ApprovalStatus == 100000001 || ApprovalStatus == 100000002))
    the not operator (!) makes your code as "if control is not disabled then set not disabled" but needs to be "if control is disabled then set not disabled", so you need to remove the ! operator.

    I suggest also to rewrite the functions in this way:

    //MakeFieldsReadOnly, this works fine.
    function AllReadOnly_onchange()
    {
    var RequestApproval = Xrm.Page.getAttribute("synact_requestapproval");
    var ApprovalStatus = Xrm.Page.getControl("synact_approvalstatus");
    var ApprovalDate = Xrm.Page.getControl("synact_approvaldate");
    
    if (RequestApproval.getValue() == 1) {
    var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; if (control.getDisabled() == false) { control.setDisabled(true); } } ApprovalStatus.setDisabled(false); ApprovalDate.setDisabled(false); } } //Make All Fields Available, nothing happens. function ApprovalStatus_onchange() { var ApprovalStatus = Xrm.Page.getAttribute("synact_approvalstatus").getValue(); if (ApprovalStatus == 100000001 || ApprovalStatus == 100000002) {
    var controls = Xrm.Page.ui.controls.get(); for (var i in controls) { var control = controls[i]; if (control.getDisabled() == true) { control.setDisabled(false); } } } }


    My blog: www.crmanswers.net




    Wednesday, July 17, 2013 8:06 PM
  • Thank you for your reply.  Put your code in and I get an error:

    <CrmScriptErrorReport>
      <ReportVersion>1.0</ReportVersion>
      <ScriptErrorDetails>
       <Message>'controls' is undefined</Message>
       <Line>8</Line>
       <URL>/%7B635096899000003448%7D/WebResources/synact_MakeAllFieldsReadOnly</URL>
       <PageURL>/userdefined/edit.aspx?etc=10021&pagemode=iframe&preloadcache=1374093109989</PageURL>
       <Function>AllReadOnly_onchange()</Function>
       <CallStack>
        <Function>AllReadOnly_onchange()</Function>


    Ken Compter

    Wednesday, July 17, 2013 8:33 PM
  • I forgot this line inside AllReadOnly_onchange and ApprovalStatus_onchange functions

    var controls = Xrm.Page.ui.controls.get();

    I fixed the before post.


    My blog: www.crmanswers.net



    • Edited by Guido PreiteMVP Wednesday, July 17, 2013 8:56 PM fixed
    • Marked as answer by kcompter Thursday, July 18, 2013 1:19 PM
    Wednesday, July 17, 2013 8:53 PM
  • That was the trick!  Works beautifully.  Thanks for the help!

    Ken Compter

    Thursday, July 18, 2013 1:19 PM