Help with script for timer

John Vo1
Tera Guru

Can someone help me with a script that will create a task in 1 week from the start date?

So for an onboarding request HR will enter a start date.  I want a task created in 1 week from that start date on the catalog item.

Here is my workflow 

This is what's in my timer.  But when I ran my test it creates the 1 week follow up task.

1 ACCEPTED SOLUTION

Steven Parker
Giga Sage

The timer activity is based on seconds when scripting.  There are 86400 seconds in a day.  So multiply that by 7 days and you get 604800.

So in your timer activity change the "Timer Based On:" field to "Script" and then use the following script:

answer = 604800;

 

That's in seconds...so you can always test it by putting 120 in there and see if it waits 2 minutes before creating your 1 week task.

 

Here is an example from our instance from a "Timer Activity" where we wait until the "Travel End Date" from a catalog item before proceeding in the workflow:

// Set 'answer' to the number of seconds this timer should wait
answer = gs.dateDiff(gs.now(), current.variables.end_date.getDisplayValue(),true);

Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

View solution in original post

6 REPLIES 6

johnfeist
Mega Sage
Mega Sage

Hi John,

What you are actually looking to do is create a request.  Catalog tasks live in the context of a requested item and requested items normally live in the context of a request.  Any tasks associated with the catalog item Onboarding - Request for Computer should be triggered by the flow associated with that item.  Since request is not a mandatory field on the requested item record you can get away with not having one, but you should check with your system admins to make sure that creating an orphan item will not cause other issues downstream.

To create what you need, try a script something like this:

var theCatalog = new GlideRecord("sc_cat_item");
theCatalog.get("name", "Onboarding - request for Computer"); //use the name not sys_id for portability
var theItem = new GlideRecord("sc_cat_item");
theItem.initialize();
theItem.cat_item = theCatalog(sys_id);
// do the other assignments like requested_for and due_date
theItem.insert();

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

 

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

John,

 

So create a request where?

 

Thanks,

John

var theRequest = new GlideRecord(sc_request);
theRequest.initialize();
//assign requested_for and any other needed fields
var theRequestedItem = theRequest.insert;

var theCatalog = new GlideRecord("sc_cat_item");
theCatalog.get("name", "Onboarding - request for Computer"); //use the name not sys_id for portability
var theItem = new GlideRecord("sc_cat_item");
theItem.initialize();
theItem.request = theRequestedItem;
theItem.cat_item = theCatalog(sys_id);
// do the other assignments like requested_for and due_date
theItem.insert();

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

So where would this script go?