Workflow : Need to delay the creation of SCTASK after RITM approval with 5 days before the set date in the form.

Rmohan
Mega Expert

Hi Snow Community,

Working on a workflow to delay the creation of SCTASK after RITM approval with 5 days before the set date in the form.

So I have a field on my Onboarding form- Start Date, which is set to be 10+ days if the request is being opened today.

The ask is to start the creation of SCTASK only when 5 business days are left to the set Start Date.

Example- Date on which request is being opened- 15th Oct; Start Date will automatically be set as- 29th Oct.(this is done)

The workflow should start at 22nd Oct.(not working).

I tried few of the Timer scripts but nothing seems to be working. Any help/suggestion would be greatly appreciated.

Thanks

7 REPLIES 7

TrevorK
Kilo Sage

One way to delay the execution of code is by putting a future-dated event in the queue, and having a Script Action called when the event is triggered (at that future time). You of course have to manage this if you want to cancel an event (e.g. ticket is cancelled) outside the predefined logic.

 

Script Action: https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/platform-events/reference/r_ScriptActions.html

Delaying an Event (gs.eventQueueScheduled): https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_SGSYS-eventQSched_S_O_S_S_O

 

If you need specific examples let me know but that's what you need to do this outside of workflow. One challenge within old workflow (no idea if Flow Designer addresses this) is that it could need to be "nudged" to trigger events and often would fail for scenarios like you mention where nothing is updated to "nudge" it.

Hi Trevor, 

 

Thank you for your response. I would be trying this but as I am quite new to ServiceNow, I might face some issues.

Can you please share some examples? It would really help me in fixing this problem.

 

Thanks

a) Create an Event in the Event Registry: https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/platform-events/concept/c_EventRegistry.html
You are simply referencing this event in (b) and (c) below.


b) Insert the gs.eventQueueScheduled code where you need it (workflow, business rule, etc.). It will reference the event created in (a): https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_SGSYS-eventQSched_S_O_S_S_O
This is pretty much the same as your typical gs.eventQueue command, just with the addition of a date/time to execute. It's a single line of code where you pass in your object so that your Script Action can work off it. I would assume you'll pass in the RITM object.


c) Create a Script Action that is triggered based on the event you created in (a). This Script Action will contain the code needed to create the Catalog Task: https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/platform-events/reference/r_ScriptActions.html
This is where you actually create the Catalog Task. If you passed in the RITM object in (b) you would be able to reference it to create your Catalog Task.

Thank you Trevor, I will try this and let you know if this works or not.