Button to lock variables on RITM form

Joshuu
Kilo Sage

Hi All,

 

We have made all the variables of a specific catalog item editable on RITM form.

Is there a way to lock all the variables through a button or any link ?

 

Please assist.

 

Thanks & Regards.

6 REPLIES 6

Sujatha V M
Kilo Patron
Kilo Patron

@Joshuu In OOB, we already have client scripts in "False" state on RITM and Catalog Task table. On activation, this will reflect for all catalog items.

 

If you want to set it for a particular catalog item then you can modify accordingly by dot walk to that item and use the syntax. 

 

SujathaVM_0-1712144006373.png

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi @Sujatha V M ,

 

Thanks for your response. Actually below is the requirement.

1. Once the request form is submitted have all variables unlocked and editable on RITM form.
2. Ability to manually lock down all the variables via a button.

 

So, I have created a UI policy to make all the variables editable on RITM form and the first point is working fine. Also, I have created a UI action button as "Lock Variables" on RITM form to lock variables manually. But that is not working properly.

below is the script I have used in the UI action script on RITM table.

 

var gr = new GlideRecord('sc_req_item');
gr.get(current.sys_id);
var itemVariables = gr.variables;
for (var i = 0; i < itemVariables.getCount(); i++) {
    var variable = itemVariables.get(i);
    variable.setReadonly(true);
    gr.update();
}
 
Please correct me If my approach is wrong. 
 
Thanks & Reagrds.

@Joshuu  :  Please refer the below link for similar way to extract the variables, 

 

https://www.servicenow.com/community/developer-forum/how-to-get-the-variables-from-the-request-item-...

 

You can push the variables and then set it to "False" using the loop defined. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi @Sujatha V M ,

 

I have added the code as below, but not working. could you please help me here.

 

 var ritmGr = new GlideRecord('sc_req_item');
    ritmGr.addQuery('cat_item', '4ad307bf87a455d0de4d7597cebb3539');
    ritmGr.query();
    //For Testing comment WHILE loop and uncomment IF loop
   // while(ritmGr.next()) {
    if(ritmGr.next()) {
        gs.print(ritmGr.number + ': ' + getVariableResponse(ritmGr));
    }


function getVariableResponse(ritmGr) {
    var list = [];
    var scOptionGr = new GlideRecord('sc_item_option_mtom');
    scOptionGr.addEncodedQuery('request_item=' + ritmGr.sys_id);
    scOptionGr.query();
    while(scOptionGr.next()) {
        list.push('Question: ' + scOptionGr.sc_item_option.item_option_new.getDisplayValue() + '\tQuestion Sys ID: ' + scOptionGr.sc_item_option.item_option_new + '\tValue: ' + scOptionGr.sc_item_option.value);
		scOptionGr.makeReadonly(true);
	}
    return list;
}
action.setRedirectURL(current);