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

Amit Verma
Kilo Patron
Kilo Patron

Hi @NathanHaywood 

 

Are you getting any error with the scheduled Job ? Also, if you want to continue with the Flow Designer approach then you can set the trigger to Daily and configure a run script action as a first node inside the flow which will check if today's date is the 1st day of Jan and so on. Based on the output of your run script, you can continue further inside the flow to generate the RITM or can terminate the flow.

 

Thanks & Regards

Amit Verma


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

NathanHaywood
Tera Contributor

Thank you Amit. I will give this a go and let you know how it goes.

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

 

 

Hi Sunil, thanks for this. What do I need to do in the Output Variables?

 

I have this, but I can't seem to find it in the Data Pill Picker back in the flow?

 

NathanHaywood_1-1704277382233.png

 

 

Kind regards