How to make one variable editable on the RITM while all others read only

Brett Vaughn
Tera Contributor

I am developing a catalog and need to have one of the variables remain editable after the approvals are received.  It only needs to be editable until the first task is completed.  Right now, I am just trying to override setting the read only property after setting all the other variables to read only.  The way I have it below is not functioning correctly.   Any assistance would be greatly appreciated. 

function onLoad() {
   var stage = g_form.getValue('sc_req_item.stage');
   if(stage == 'request_approved' || stage == 'completed'){
        setTimeout(function () {
            g_form.setVariablesReadOnly(true);
        }, 500);
      }
   //Revert legal hold to editable
   g_form.setReadOnly('legal_hold', false);
   g_form.setDisplay('legal_hold',true);
}
1 ACCEPTED SOLUTION

Out of curiosity, if you edit the code to look like below, does it execute the way you'd like it to?

 

function onLoad() {
   var stage = g_form.getValue('sc_req_item.stage');
   if(stage == 'request_approved' || stage == 'completed'){
        setTimeout(function () {
            g_form.setVariablesReadOnly(true);
            
            g_form.setReadOnly('legal_hold', false);    //Revert legal hold to editable
            g_form.setDisplay('legal_hold',true);
        }, 500);
      }

}

 

 



If I've at all helped, please return the favor by clicking the thumb next to my post. Thanks!

View solution in original post

9 REPLIES 9

Ok, I realized I didn't try disabling the UI Policy after I made your changes.  That seemed to work. But now it is allowing all of the variables on the SCTask to be editable.  So I am going to do some more updates tomorrow to see if I can get it where it is just the legal_hold field that is editable.  Thank you!

Awesome! Glad you've made some headway. If tomorrow comes around and something gets stuck, come on back and we can keep working with it.



If I've at all helped, please return the favor by clicking the thumb next to my post. Thanks!

@Brett Vaughn 

Did you get a chance to check my below script?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes thank you!

Ankur Bawiskar
Tera Patron
Tera Patron

@Brett Vaughn 

you can use Display business rule on sc_task table-> get the RITM stage using this

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    g_scratchpad.stage = current.request_item.stage.toString();

})(current, previous);

then use Normal onLoad client script on sc_task table and not Catalog client script

function onLoad() {

    if (g_scratchpad.stage == 'request_approved' || g_scratchpad.stage == 'completed') {
        setTimeout(function() {
            g_form.setVariablesReadOnly(true);
        }, 500);
        g_form.setReadOnly('variables.legal_hold', false);
        g_form.setDisplay('variables.legal_hold', true);
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader