- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 10:14 PM
Hello All,
Currently we ar using this script to make a variable mandatory upon closing SCTASK.
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('state') == 3){//Closed Complete
if((g_form.getValue('what_needs_to_be_changed') == 'Name') && (g_form.getValue('short_description') == 'Update Account Details: Fulfill Request')){//to make this variable mandatory when only this task closes
g_form.setMandatory('new_userid', true); //set the variable for new user form mandatory
var newUserid = g_form.getValue('new_userid');
var newID = newUserid.trim();
g_form.setValue('new_userid', newID);
g_form.setMandatory('new_cn', true); //set the variable for new user form mandatory
var newCN = g_form.getValue('new_cn');
var newCN2 = newCN.trim();
g_form.setValue('new_cn', newCN2);
if(g_form.getValue('new_userid') == '' || ('new_cn') == ''){ //if new user form is empty or blank it will give error message
alert('Please input the New Userid and CN');
return false;
}
}
}
}
but we have a problem on the short description, if the requestor/opened by user language is not english the script will return false since we set it in english.
If i will set the RITM "stage" as condition, how would i do that?
tried to change the line here to:
if((g_form.getValue('what_needs_to_be_changed') == 'Name') && (g_form.getValue('stage') == 'Fulfillment')){//to make this variable mandatory when only this task closes
but didn't work 😞
Please help ^__^
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 10:53 PM
Hello,
Are the fields new_userid, new_cn and what_needs_to_be_changed the catalog task table fields for catalog item variables. I think those are catalog item variables and if yes, then you need to read their value as g_form.getValue("variables.VARIABLE_NAME"). ex: g_form.getValue("variables.new_userid").
Regarding short description language issue, you can create a display business rule on SCTASK table and add requested item's stage value to the g_scratchpad. Then in your client script, you can use same g_scratchpad value in the condition.
This video provides details example about g_scratchpad usage How To Use g_scratchpad in ServiceNow | ServiceNow Training Videos - YouTube
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2022 02:24 AM
Hello @Al-jhon
Couple of updates needed on client script:
1. uncheck the "Applies on requested item" field
2. in script include, you are reading request_item sys_id with parameter as sysparm_item. so in client script you need to pass value in that parameter. Update line 8 of client script as below:
gStage.addParam("sysparm_item",g_form.getValue("request_item"));
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2022 10:53 PM
Hello,
Are the fields new_userid, new_cn and what_needs_to_be_changed the catalog task table fields for catalog item variables. I think those are catalog item variables and if yes, then you need to read their value as g_form.getValue("variables.VARIABLE_NAME"). ex: g_form.getValue("variables.new_userid").
Regarding short description language issue, you can create a display business rule on SCTASK table and add requested item's stage value to the g_scratchpad. Then in your client script, you can use same g_scratchpad value in the condition.
This video provides details example about g_scratchpad usage How To Use g_scratchpad in ServiceNow | ServiceNow Training Videos - YouTube
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2022 12:00 AM
Hello Ahmmed Ali,
I followed your isntruction, i created a display BR on SC_REQ_ITEM table:
and update the line to:
if((g_form.getValue('what_needs_to_be_changed') == 'Name') && (g_scratchpad.stage = "Fulfillment")){
and it WORKED!
but another question, what is the difference of script includes (callable) and g_scratchpad?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2022 12:40 AM
Hello @Al-jhon
Client callable Script include are using to run server script from client side ondemand. i.e you can call script include in any of the client scripts. This is more suitable when you want dynamic data to be pulled from server side.
Business rule with g_scratchpad is used when you have you need to pull static data from server side. This will reduce client-server interaction thus improving performance.
Based on use you, either of one can be used.
For example: If you want logged in user's manager and email ID in client script, instead of script include and calling that in client script, you can user g_scratchpad to put logged in user details in the object.
Assume you are using this data in on-change client script, then for each time value changes the client script runs and it reads data which is already available in g_scratchpad (if script include was used, then for each time it will have server-client interaction.)
But assume you want caller of incident's manager details in client script, then it would be ideal to use script include because the caller field can be changed at client side, and we need latest caller's details (compared to g_scratchpad one which will be static details of initial caller).
Hope this clears the concept.
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2022 12:55 AM
Thank you so much @Ahmmed Ali .