
- 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-19-2020 04:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 05:22 AM
Not sure what you're saying here, is the workflow now working properly? If you are expecting a log message but not getting one then there must be one missing, i don't know what your WF needs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 07:27 AM
Hi David,
I checked your approach it stops the workflow in the "Wait for Condition" with the condition I shared previously, but when I close the task it doesn't update the RITM any more and the workflow is still running.
Regarding workflow, I was just saying that maybe I need a log message to complete the workflow correctly. Again I am quite new to development I don't get all logic yet maybe I am missing something on workflow side?
Here is the screen of "Wait for Condition" maybe I need a different stage there, since I put "Completed" stage in my log message.
I just guessed it might be logical way maybe I am totally wrong.
Thanks in advanced for ideas they were awesome, if you have anything else to add here, feel free to share, just don't want to put my task on you since you have already helped me greatly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 07:47 AM
I don't think you need a log message, if you need a stage set on a workflow activity you could change the end activity to have the completed stage.
If the request item isn't being closed down when the task is closing you'll need to either figure out why not or create your own rule to close down the parent task. Something like the below would work in an after update business rule triggering when state changes to closed complete but this would apply to all request items unless you put in some conditions to restrict it.
(function executeRule(current, previous /*null when async*/) {
if(!openTaskChecker(current.request_item)){
var gr = new GlideRecord('sc_req_item');
if(gr.get(current.request_item)){
gr.state = current.state;
gr.update();
}
}
function openTaskChecker(requestItem){
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', requestItem);
gr.addQuery('active', true);
gr.setLimit(1);
gr.query();
return gr.hasNext();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2020 09:09 AM
Thanks, David!
Great advice. For me it all sounds quite complicated, so I will probably hand over to our developers who are true developers to evaluate the case since as you are saying this business rule has a global impact and we will need to restrict it.
Just happened that I became a sort of developer, although I am a BA and have no technical background. But, I finally got a chance to come back to BA activities locally in Ukraine. Things are moving so quickly that even this became possible.
Have a good evening,
Victoria