Create Catalog task after 30 days from the selected date in variable

dileep0146
Tera Contributor

Hi All,

 

I have to create the Catalog task after 30 days from the selected date in the variable.

 

for example, If I select today's date in the variable and the catalog task should create after 30 days. (i.e, on July 24th).

var termDate = current.variables.term_date;
if (termDate) {
    var targetDateTime = new GlideDateTime(termDate + "00:00:00");
    //wait until 30 days after Disable IT Access Date
    //targetDateTime.addDaysUTC(1);
	targetGDT.addDaysLocalTime(30);
    var currentDateTime = new GlideDateTime();
    var diffSeconds = Math.floor((targetDateTime.getNumericValue() - currentDateTime.getNumericValue()) / 1000);
    answer = diffSeconds > 0 ? diffSeconds : 0;
} else {
    answer = 0;
}

I have created Timer activity and the Timer based on Script, Can you please check and suggest.

And also, please suggest how to test it.

Thank you 

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @dileep0146 

 

Refer:

https://www.servicenow.com/community/developer-forum/workflow-how-to-create-task-at-certain-date/m-p...

 

https://www.servicenow.com/community/developer-forum/generate-a-catalog-task-based-on-a-specific-var...

 

https://www.servicenow.com/community/developer-forum/how-to-create-catalog-task-on-particular-date-t...

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Ankur Bawiskar
Tera Patron

@dileep0146 

this link has approach

Create a task in flow designer from date variable field on catalog item form 

also check this

you can make the flow wait till that date variable and then create the task

it's simple logic and you can achieve it

check this blog and enhance as per your requirement

Flow Designer : Making the flow wait until a specific date time based on a catalog variable 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

vaishali231
Kilo Sage

Hey @dileep0146 

Try this:

var termDate = current.variables.term_date;
if (termDate) {
    var targetDateTime = new GlideDateTime(termDate + " 00:00:00");
    // Add 30 days to the selected date
    targetDateTime.addDaysLocalTime(30);
    var currentDateTime = new GlideDateTime();
    // Return the number of seconds the workflow should wait
    var diffSeconds = Math.floor(
        (targetDateTime.getNumericValue() - currentDateTime.getNumericValue()) / 1000
    );
    answer = diffSeconds > 0 ? diffSeconds : 0;
} else {
    answer = 0;
}

 

************************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh

Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb