Help with script in custom flow action - need to return value with date & time

Lon Landry4
Mega Sage

I have a custom action for flow designer that nearly works, the correct date is returned but no time.

Action - Set date to first of month

Inputs:

setDate01.png

 

Label Next audit date & Name u_next_audit_date with Type Date/Time

 

Script step

scriptStep.png

 
Outputs:
outputs.png
First of month date (ill from script step)
Warning in script step.
Encountered undeclared output variable: result_date_time

What is returned - (Correct date but no time stamp...)
good.png
Any ideas?
 
6 REPLIES 6

Gangadhar Ravi
Giga Sage
Giga Sage

@Lon Landry4  Use getDisplayValue() insted of getValue(). Please see below updated script.

 

(function execute(inputs, outputs) {
    // Parse the input date
    var inputDate = new GlideDateTime(inputs.u_next_audit_date);

    // Extract year and month from the input date
    var year = inputDate.getYear();
    var month = inputDate.getMonth() + 1; // Months are 0-indexed

    // Create a new GlideDateTime for the 1st of the month at 2:00 AM
    var newDateTime = new GlideDateTime();
    newDateTime.setValue(year + '-' + (month < 10 ? '0' + month : month) + '-01 02:00:00');

    // Set the output (use getDisplayValue to return both date and time)
    outputs.result_date_time = newDateTime.getDisplayValue();
})(inputs, outputs);

Please mark my answer correct and helpful if this works for you.

I changed the code as mentioned, but I am seeing the same error...

When I test the action - I see the correct Date & Time - the time is being lost when passed back to flow.

Gangadhar Ravi
Giga Sage
Giga Sage

@Lon Landry4  Please check if this post is helpful 

https://www.servicenow.com/community/developer-forum/next-action-date-time-transform-not-working-in-...

 

Please mark my answer correct and helpful if this works for you.

Tried linked suggestion- here is new code - but same error