- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 03:07 AM
Hi,
I'm curiouse how can I create loop over workflow by script. I've got run script thats sends email and weekly timer. I wanna loop it four times until end of the month and then go to begining. I didn't find any out-of-the-box solution in the way of activities for loop. Below is my run script to send emails
var callers = [];
var encodedString = 'active=true^state=-5';
var gr = new GlideRecord("change_request");
gr.addQuery(encodedString);
gr.query();
while (gr.next()) {
callers.push(gr.requested_by.email.toString());
}
var arrayUtil = new ArrayUtil();
callers = arrayUtil.unique(callers);
for(var i = 0; i < callers.length; i++){
gs.eventQueue('reminder.event', null, callers[i], '');
}
Maybe there is another simpler way to solve this ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 09:13 PM
Hi
If I stay on a scheduled job, there are more options.
a) you create different schedulef jobs and they run on different schedules (not sure, if you can configure a workflow to only run at month end)
OR
b) you handle your scheduling logic INSIDE ONE scheduled job in a script which runs DAILY , e.g. To check the last day of the month and then run the specific logic.
Personally I would choose option b)
This would keep all logic regarding your one requirement one one place.
And remember, that workflows are not intended to run forever.
Let me know if that answered your question and mark my answer as correct and helpful.
BR Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 01:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 01:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 01:51 PM
Hi
It sounds as if you want to go through this 4 week schedule endlessly.
Doing that in a workflow is not a good idea, because workflows are counting the number of activities executed.
If that passes a certain number, the workflow will be canceled.
Even if you manage to implement it in that way, and looks good in the first moment, it will fail after some time.
Then, you will start researching.
Instead, create a scheduled job, which controls your 4 different scenarios by script.
This will run endlessly. Let me know if you need assistance with scripting that job.
Please let me know if that answered your question and mark my answer as correct and helpful.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 02:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2020 02:17 PM
Hi
Of course, you can create loops in your workflow, but again....
Having workflows that runs "endlessly" is not a good design.
This does not make sense to implement as a workflow.
I recommend to use different options.
Why do you think that you can not handle the schedule job?
Let me know.
BR Dirk