Start new workflow on old records.

velvet
Mega Guru

I created a  2 workflow that send emails to groups and assigned to, to assigned the task and update the task.  The issue I have is for the records that were created before the workflow was created.  So I ran a background script, to start the workflows on the old records.  The condition for the workflows is if the created date is more than 3 days old and does not have an assign to, send email to the group.  The second workflow sends email after assignment to update task if 3 days has passed.

Here is the script that is not starting the workflows on the older records.

var gr = new GlideRecord('sc_task');
gr.addQuery('sys_created_on', '>', '2019-07-08'); // add your query to filter old records
gr.query();
while(gr.next()){
new Workflow().restartWorkflow(gr);

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Was there a workflow on the sc_task table? Or was it on the sc_req_item table?

If so, you'd need to query sc_task to get relevant records, then nest a query to sc_req_item to find those actual items and restart the workflow at that level.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

The workflow works... I am running a script for the old records that were created before the workflow.  I need to start the workflow on the old records, so the above script is for the old records

And yes the workflow is on the task table

Yea, I didn't say the workflow wasn't working, I simply asked where the workflow was hosted, what table. And you've responding saying it's on the sc_task table, so good. Just making sure.

As far as how to restart, the script above for this line:

new Workflow().restartWorkflow(gr);

Is correct...you'd just want to ensure you're actually getting returns with your query. Have you checked that? Have you placed a log statement to see that you're actually finding records?

You're also missing an end bracket, but maybe you didn't copy/paste all the way.

So first...check your query and see if you are finding records. I'd personally recommend going to the list view for sc_task, set up your filter how you want it, then in your breadcrumb on the last entry of it, right-click that blue link/breadcrumb and choose "copy query", then in your glide query here, change it to an encoded query like

gr.addEncodedQuery('paste query here');

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!