Flow designer Action script to take Date input and give output as Day and Month from the date

Dee S
Giga Guru

I've a requirement where I'll give input some Date and I want to get Day and Month of that date. Need script help for that

Example:

input: 2022-08-17

Output:

Day: 17

Month: 08

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello @Dee S 

You can follow the below steps.

Go to Flow designer click on create new Action.

1. Create action input step:

find_real_file.png

2. click on + icon and slect Script to create a Script action. Create Input Variables for script step to provide the input to the script. Click on Data pill picker to add the value to this variable from Inputs--> Date time variable. (ie. variable from step 1)

find_real_file.png

In script specify the below script:

(function execute(inputs, outputs) {
  var dateGDT = new GlideDate();
  dateGDT.setValue(inputs.date_value + "");
  outputs.month_value = dateGDT.getMonthNoTZ();
  outputs.date_value = dateGDT.getDayOfMonthNoTZ();
})(inputs, outputs);

Create Output vairable for script step as show below:

find_real_file.png

3. Create Outputs as shown below. You need to first create Output variables. Click on Exist Edit mode button. Then assign the value to those variable by clicking on Data pill picker icon and using the variable created as output variables in step 2.

find_real_file.png

find_real_file.png

Click on Save. Then to test the action click on Test button. Provide the date value and then check the values in flow execution:

find_real_file.png

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.

Thanks

View solution in original post

6 REPLIES 6

H_9
Giga Guru

Hello Dee,

 

You can use following code for getting Day and the Month. Try it in the background script.

gs.info(new GlideDateTime("2022-08-17").getMonthLocalTime());
gs.info(new GlideDateTime("2022-08-17").getDayOfMonthLocalTime());


OUTPUT:
8
17

For more information, please refer https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/c_APIRef

Please mark the answer correct if it helps. 🙂

Thanks.

Thanks. 🙂

I want to write script in flow designer action not a normal java script. How to pass inputs and outputs in flow designer action

u_birthdy field type is "date"

Mahendra RC
Mega Sage

Hello @Dee S 

You can follow the below steps.

Go to Flow designer click on create new Action.

1. Create action input step:

find_real_file.png

2. click on + icon and slect Script to create a Script action. Create Input Variables for script step to provide the input to the script. Click on Data pill picker to add the value to this variable from Inputs--> Date time variable. (ie. variable from step 1)

find_real_file.png

In script specify the below script:

(function execute(inputs, outputs) {
  var dateGDT = new GlideDate();
  dateGDT.setValue(inputs.date_value + "");
  outputs.month_value = dateGDT.getMonthNoTZ();
  outputs.date_value = dateGDT.getDayOfMonthNoTZ();
})(inputs, outputs);

Create Output vairable for script step as show below:

find_real_file.png

3. Create Outputs as shown below. You need to first create Output variables. Click on Exist Edit mode button. Then assign the value to those variable by clicking on Data pill picker icon and using the variable created as output variables in step 2.

find_real_file.png

find_real_file.png

Click on Save. Then to test the action click on Test button. Provide the date value and then check the values in flow execution:

find_real_file.png

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. This will help others with similar issue to find the correct answer.

Thanks