- 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-26-2022 02:14 AM
Hello @Ahmmed Ali , im trying to create script include and the data passing is null.
can you please take a look on my codes and check?
Script Includes:
Catalog client script:
the addinfomessage gives me null value.

- 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-26-2022 02:34 AM
@Ahmmed Ali you're the man! 🙂 Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 09:45 AM
Hello @Ahmmed Ali
I have a little problem with my recent code:
the return false; is not working. Closing task still proceeds but it makes the variables mandatory and the alert displays.
where should i put the return false; line to avoid closing the SCTASK?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 11:18 AM - edited 11-15-2022 11:18 AM
Hello @Ankur Bawiskar
Do you have solution for this?
I can't prevent form to submit with GlideAjax. check my code....
function onSubmit() {
//Type appropriate comment here, and begin script below
var gStage = new GlideAjax('VSHMandatoryVariablesAJAX');
gStage.addParam('sysparm_name', 'getStage');
gStage.addParam('sysparm_item', g_form.getValue('request_item'));
gStage.getXML(_response);
function _response(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
alert(answer);
if(g_form.getValue('state') == 3){//close complete
if((g_form.getValue('what_needs_to_be_changed') == 'Name') && (answer == 'fulfillment')){
if((g_form.getValue('new_userid') == "") && ('new_cn') == ""){//if new user form is empty or blank it will give error message
g_form.setMandatory('new_userid', true); //set the variable for new user form mandatory
g_form.setMandatory('new_cn', true); //set the variable for new user form mandatory
alert('Please input the New Userid and CN');
return false;
}
}
}
}
}