Add condition to client script

dvelloriy
Kilo Sage

Hi All,

I have 2 OOB client scripts - Variable Editor Readonly

on RITM and SC TASK table.

This is making all variables read-only on RITM and sc task.

Requirement is to restrict these 2 client scripts only to few catalog items. (where catalogs = Procurement).

How can i add this condition to the client scripts?

Thanks

9 REPLIES 9

Hi Anurag,

Not sure if i fully understood the solution here. could you please expand?

@dvelloriy You can write a display business rules on RITM and SC_Task tables and put the condition mentioned by Anurag in the script. Then set a g_scratchpad variable accordingly (True/false) and check this variable inside your client script. To know more about display business rule, please refer to https://www.servicenow.com/community/developer-articles/display-business-rule-and-g-scratchpad/ta-p/....

 

Hope this helps.

Sandeep, i would need further help in defining the scratchpad variable.

 

So I need to create a Display BR on SC TASK

1. I will add a condition Request Item. Item. Catalogs = Procurement

2. Under Advance section, i will add add a script to initiate scratchpad variable.

g_scratchpad.value = "true";

3. Then in my global client script, i will insert scratchpad created above:

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_scratchpad.value = "true") {
g_form.setVariablesReadOnly(true);

}
}

 

Will this work? Please advise.

 

@dvelloriy Yes, ideally this will work added a small change in the script.

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_scratchpad.value == "true") {
g_form.setVariablesReadOnly(true);
}
}

Guess you are covered, do you still have any more question?

-Anurag