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

Hi

To be honest, if you just send the same notification every 7 days, like I see in your code, you just need to put your code to the scheduled job.

That's it.

Let me know if that answered your question and mark my answer as correct and helpful.

BR Dirk

Hi @Dirk 

For automatize send emails every 7 days your solution suits well but my task require more functionality beside weekly reminder e.g. send email last day on month or send email after changing form status.

Is that possible manage by Scheduled Job only? I supose not, am I right?

I need find put together those functionality in one workflow, is that possible ?

Or maybe other solution can manage my issue.

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

thanks @Dirk for sharing your ideas

 

You are welcome. I am happy to help you. Have fun BR Dirk