How to trigger workflow for existing records

Manju Shree
Tera Expert

Hi All,

I have a requirement to trigger workflow once in a year (July 1st). The workflow needs to send an approval for all the existing records. I created a scheduled workflow that will run daily but will check the condition if Today's date is July 1st. 

If yes is returned then workflow will be executed but the problem is the approval is not triggered for all the records, only for newly created record the workflow is executing. 

find_real_file.png

Something is missing out here. Do let me know how to trigger this workflow for existing records.

Thanks in advance.

Regards,

Manju Shree

7 REPLIES 7

Martin Ivanov
Giga Sage
Giga Sage

Hello,

Please refer to this thread.

Please Mark Correct and Helpful if my answer helps you resolve your issue. Thanks!

Martin Ivanov
Community Rising Star 2022


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You can use fix script to run this; But you need to be sure for which records it has to run.

The link shared by Martin will help you. It has script shared by me which you can refer and let us know your updates.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for your reply.

The below script from the other thread is working as expected

triggerWorkflow();

function triggerWorkflow(){

try{
var rec = new GlideRecord('table'); // give your table name
rec.addEncodedQuery('YOUR QUERY HERE FOR OLDER RECORDS');
rec.query();

while(rec.next()){
var wf = new Workflow();
wf.startFlow(wf.getWorkflowFromName('give the workflow name'), rec, 'update'); // give workflow name here
}
}
catch(ex){
gs.info('Exception'+ex);
}

}

I do have another question, can we trigger the workflow only from scheduled workflow? I need not want that particular workflow to work when record is inserted.

Regards,

Manju Shree

Hi,

then why to create workflow?

why not do the task in some other script?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader