Loop activity over workflow

miro2
Mega Sage

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], '');
}

 find_real_file.png

 

Maybe there is another simpler way to solve this ?

1 ACCEPTED SOLUTION

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

View solution in original post

14 REPLIES 14

@Mark Roethof Thanks for sharing idea how to solve this issue, could you check my solution (just above)?

miro2
Mega Sage

@miro 

DirkRedeker
Mega Sage

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

@Dirk Is there any possibility to create script loop as a activity in workflow and add it at workflow directly? I don't think I can handle the scheduled job script

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