
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 02:54 AM
Dear All,
I am very new to scripting, please suggest how to correctly write a script where I need to use GlideRecord call twice.
The script is here:
// value.addQuery('sys_id', current.number);
// value.query();
// while (value.next()) {
var catVar = current.variables.select_all_tw_software_needed.toString();
var res = finalVal.split(',');
var len = res.length;
{
for( var i=0; i<len;i++)
{
var table = new GlideRecord('u_asr_apps_to_users');
table.initialize();
table.u_nameid_servicenow_applicaion = res[i];
//table.u_parent_sc_task = value;
table.insert();
}
}
}
The logic is to get current SCTASK number based on sys_id of the record and inset it in a new custom table 'u_asr_apps_to_users'. The 1st part of the script isn't working.
I assume I am missing some important element I am trying to query sc_task table and get the task number,but I am not sure that I am doing it correctly. Please help!
Thanks,
Victoria
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 05:13 AM
OK so you could try moving the script in your run script activity to the script section on the catalog task activity, not 100% sure if that would work though, if it does you wouldn't need the glide record you could just reference current.number as the parent task record.
If that doesn't work you'll need to add a wait for condition in your workflow after the run script otherwise it will skip right through to the end. Wait for conditions are only checked when the current record is updated so you'll need something to change on the parent request item record once the task is done in order to satisfy that condition. I think OOB config marks the request item as closed complete when the all tasks are completed so you might be able to just check for when state changes to closed complete. If not you'll have to find something else to change so that the workflow checks the condition.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2020 10:20 AM
Thanks, David!
I will try all these tomorrow.
Many thanks have a great weekend!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 02:46 AM
Hi David,
I know it was awhile, but I am just trying to test your approach. I have created the Wait for Condition in my Workflow and trying to make it wait for the situation when the state of the Task is changed to "Close Complete".
For this I have written this script since I have little coding experience, I would like to know if it makes sense, if possible.
answer = new GlideRecord ('sc_task');
answer.addQuery('state','4');
answer.query();
while (answer.next()) {
answer = true;
}
Will appreciate your feedback, hopefully you will see this message and will find a chance to answer.
Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 03:07 AM
Hi Victoria,
The condition in the wait for activity will only be checked when the current record is updated, the current record in this case is the request item on which the workflow is running.
So, you need something in place to update the request item when the task is closed and your wait for activity needs to be aligned to look out for that change.
I'm not sure if it's OOB config or something i've customised but request items on my instance move to closed complete automatically when all tasks are closed. It's worth testing that to see if the same is true on your instance, then your wait for condition can just look for when state changes to closed complete.
Cheers
Dave

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 04:26 AM
Hi David,
Thanks a lot for an answer.
I kind of got what you are saying, but have only vague idea how to get to the desired state. I know I need to have a trigger to update something on the RITM side, but is there a need to create a custom field for this or how to get to this?
Yes, on my instance OOB behavior is that RITM moves to state 3 "closed complete" only when SCTASK record is set to state 3 "closed complete" automatically.
I did following changes, but not sure any of them might help (will test the 1st scenario now) and let you know, but for the 2nd scenario is with a script, I just letting you know it, so you have an idea and might guide me a bit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 05:22 AM
This condition in the wait for activity should work just fine.