Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding script to Flow Designer to set when record is created

NathanHaywood
Tera Contributor

Hello,

 

I have a requirement to have a record (RITM) automatically generated on the 1st day of January, April, July and October. The triggers in Flow Designer are not that specific and therefore I am wondering if I can use a script, such as the one below, in Flow Designer to specify when the record is created?

 

var objDate = new GlideDateTime();
var month = objDate.getMonthUTC();
gs.log("Current month - " + month);

 

if (month == 1 || month == 4 || month == 7 || month == 10 || month == 12)

 

 

Note, this script is taken from an attempt at completing this requirement as a Scheduled Job, but the Scheduled Job doesn't generate the RITM as intended. It'd be easier if I could add this script into FD and complete the requirement this way.


Many thanks in advance.

1 ACCEPTED SOLUTION

SunilKumar_P
Giga Sage

Hi @NathanHaywood, Can you try the below steps?

1. Create an Script Action to check the month

(function execute(inputs, outputs) {
    var correctMonth = false;
var objDate = new GlideDateTime();
var month = objDate.getMonthUTC();
if (month == 1 || month == 4 || month == 7 || month == 10 || month == 12){
    correctMonth = true;
}
outputs.good_to_go = correctMonth;
})(inputs, outputs);

SunilKumar_P_0-1704276181749.png

 

2. Flow steps:

SunilKumar_P_1-1704276265231.png

 

Regards,

Sunil

 

 

View solution in original post

7 REPLIES 7

Hi @NathanHaywood 

 

You need to create an output variable good_to_go as suggested by @SunilKumar_P  and then it would be available in your flow.

 

Thanks & Regards

Amit Verma


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

Hi Amit, thank you.

 

I have created an Output Variable as below:

 

NathanHaywood_0-1704277871891.png

 

NathanHaywood_1-1704277875114.png

 

What do I need to configure in terms of Action Output?

 

Thanks

Hi @NathanHaywood 

 

Now you can make use of this good_to_go variable in your flow to evaluate the If condition. Please refer the flow snip shared by @SunilKumar_P  to configure the if condition.

 

Thanks & Regards

Amit Verma


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