Starting a Workflow on a specific date, as decided by a record

MartinH11039338
Tera Contributor

Hello!

 

I am trying to get a Workflow to start up on a specific date, in this case, decided by the date added to a record. Basically, the user will indicate a date that they would like work to be done, and that will be on the record on our custom table, we can then use that date (- a few hours) to kick off different workflows accordingly to our planned schedule. This is a custom built onboarding solution, but preferably I'd like to use out of the box capabilities for the workflow/date function itself.

 

The idea that this way will make it more clear what is happening to the user filling out the record, and also to not have workflows sitting idly by and waiting. I realize I can use the date and a wait function in the workflow already, but I'm considering if it's better practice to not have several waiting workflows? Or is the impact so minor it doesn't really matter?

 

Thanks in advance!

2 REPLIES 2

Naveen20
ServiceNow Employee

Try this Scheduled Flow + Subflow pattern in Flow Designer. 

Step 1 — Add a flag field to your custom table

Add a true/false field like u_workflow_initiated (default: false) on your custom onboarding table. This prevents duplicate triggers.

Step 2 — Create your action subflows first

Build separate subflows for each onboarding workflow you need to kick off (e.g., "Onboarding - IT Setup", "Onboarding - Facilities Prep"). Each subflow takes the record's sys_id as input and does the actual work. This keeps things modular.

Step 3 — Build the Scheduled Flow

  • Trigger: Schedule → set to run hourly (or every 30 minutes depending on your precision needs).
  • Action 1: Look Up Records on your custom table with this condition:
u_target_date minus your offset <= gs.nowDateTime()
AND u_workflow_initiated = false
AND active = true

For the date offset, use a Script step right before the lookup to calculate the comparison date:

var targetDate = new GlideDateTime();
targetDate.addSeconds(-3 * 3600); // subtract 3 hours (adjust as needed)
return targetDate.getValue();
  • Action 2: For Each Record in the result set:
    • Set u_workflow_initiated = true on the record (do this first to prevent re-processing on the next run).
    • Use a Decision or If/Else to determine which subflow to call based on a field like u_onboarding_type.
    • Call the appropriate subflow, passing the sys_id.

Step 4 — Handle date changes gracefully

Add a simple Business Rule on your custom table: if u_target_date changes, reset u_workflow_initiated back to false. That way the scheduled flow will re-evaluate it on its next run. In the subflow, add a check at the start — if a previous onboarding process was already in motion, cancel or clean it up before restarting.

Step 5 — Observability

Add a Flow Execution log or update a journal field on the record when the scheduled flow picks it up. Something like "Onboarding workflow initiated by scheduled flow at [timestamp]." This gives your end users and admins a clear audit trail.

Ankur Bawiskar
Tera Patron

@MartinH11039338 

since you mentioned you are using flow and would like to wait then this is your approach

1) let the flow trigger as soon as record created/updated and then use Wait for Condition and wait till the date is reached

OR

2) create a subflow and add your logic and then run a daily scheduled job which iterates your table records and checks if today's date matches the start date, if yes then trigger subflow from script

try {
    var inputs = {};
    // Replace 'subflow_name' and input names
    inputs['subflow_input_name'] = current; // Passing current record

    // Run subflow synchronously (waits for completion)
    var result = sn_fd.FlowAPI.getRunner().subflow('scope.subflow_name').inForeground().withInputs(inputs).run();
    
    // Get outputs if necessary
    var outputs = result.getOutputs();
} catch (ex) {
    gs.error("Error: " + ex.getMessage());
}
Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader