- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 05:25 AM
Hi,
I have been trying to set a value on my requested item form through an OnSubmit catalog client script, but to my surprise i'm unable to set it.
I'm wondering what went wrong, i have also included a timer for 30 secs on the workflow which didn't give any results.
Below is the code snippet
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('var_req') != ''){
g_form.setValue('u_input','4 hours');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:12 AM
As stated earlier, you will not have direct access to the created item from client script. You would need to create a hidden variable, set it. Then it would get pushed into the field on the target record through naming convention.
OR, you can use the script within the catalog item definition. I posted a image of the script field. You would have access to producer variables and the current target record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:00 AM
One other thing, when you are dealing with client script, you can debug it as most browsers have developer tools. You can put a break-point and step through the code and ensure that the setValue line is actually being run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:03 AM
Thanks Mihir and Grzegorz Chwalek for replying to this post. I cannot do this in the workflow as my workflow is dynamic and is being used for more than one catalog item.
I'm looking for a way to set this through OnSubmit client script. The only problem i see with the above script is, the value doesn't get set when the record is created but gets set if i update the request item record.
To give more clarity on this "var_req" is the variable name and "u_input" is a field on the requested item.
Thanks,
Srikanth Varma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:09 AM
You should then write business rule on sc_req_item table.
When: on insert
Script:
if(current.variables.var_req != ''){
current.u_input = "4 hours";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:11 AM
You can add one more condition in the if statement provided by me in the previous comment like
current.cat_item == '9d925c166f61fd0022a309c54b3ee4c9'
in place of the sys_id write the sys_id of your catalog item from maintain items.
Then this script will execute only for this specific catalog item.
Thanks,
Mihir

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2016 06:14 AM
Probably don't want to hard code sys_ids, it is against best practices:
http://wiki.servicenow.com/index.php?title=Coding_Best_Practices#Do_Not_Use_Hard-Coded_Values