The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Catalog item variables editable for Approvers in the RITM

Tamilvanan T
Tera Contributor

For a catalog item, when the request is submitted the RITM is created and the approval is triggered for two approvers, At this approval stage the RITM variables should be editable for the two approvers in the RITM for that particular Item. 

I have tried using the catalog client script but it's not working 

Catalog client script: 

    var approvalState = g_form.getValue('sc_req_item.approval');
    var approvers = g_form.getValue('sysapproval_approver.approver');

    if (approvalState == 'requested' && approvers == '39954b451b960c105ed2b888cc4bcb9d' || approvers == 'd0dc64741b6b7510857697d58d4bcb7e') {
        g_form.setVariablesReadOnly(false);
    } else {
        g_form.setVariablesReadOnly(true);

    }
}
 
Kindly provide a suggestion on how can we achieve this.
 
Regards,
Tamilvanan T
1 ACCEPTED SOLUTION

@Tamilvanan T 

my below response should help you with the script.

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

View solution in original post

4 REPLIES 4

Anand2799
Giga Guru

Hi @Tamilvanan T ,

 

On which table you are creating this client script?

Is the RITM variables read-only for all users?

Verify if write roles field is restricting editing of these.

 

It is not a best practice to use hard coded sys_id's.

If you want users to modify variables it is always a good option to create a task, add variables to the task and make them editable

 

Thanks

Anand

I'm using the catalog client script for that particular catalog item i want the variables should be editable for the approvals. 
Yes, the RITM variables are read-only for all users.

@Tamilvanan T 

my below response should help you with the script.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Tamilvanan T 

you should use normal onLoad client script on RITM and not catalog client script

Also use Display business rule to get the approvers for that RITM

Business Rule:

Condition: Item [IS] Your Item Name

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

    // Add your code here
    var arr = [];
    var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery("sysapproval", current.sys_id);
    gr.query();
    while (gr.next()) {
        arr.push(gr.getValue('approver'));
    }
    g_scratchpad.approvers = arr.toString();

})(current, previous);

Client Script:

function onLoad() {

    var loggedInUser = g_user.userID;
    var arr = g_scratchpad.approvers.toString().split(',');
    if (arr.indexOf(loggedInUser) > -1 && g_form.getValue('approval') == 'requested') {
        g_form.setVariablesReadOnly(false);
    } else {
        g_form.setVariablesReadOnly(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