- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:28 AM
I created a Flow Designer Custom Action with the goal of comparing two glidedatetimes and determining if 50% of the time had been exceed.
When I test with the My script keeps returning false no matter what dates input.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 09:19 AM
Hello @Manny11
The script you've provided has a few small issues, but it can be easily fixed. Below are some key changes to improve the functionality:
- There are inconsistencies in the method names. It should be getNumericValue() instead of getNumericalValue().
- GlideDateTime.subtract() returns a GlideDuration object, and it should be used properly for numerical comparison.
Here's an updated version:
(function execute(inputs, outputs) {
// Inputs
var start_date = inputs.start_date; // Assuming this is a string in "yyyy-MM-dd HH:mm:ss" format
var end_date = inputs.end_date; // Same format as above
// Calculate the time difference in seconds
var timeDifferenceInSeconds = gs.dateDiff(start_date, end_date, true);
// Calculate if 50% of the time has elapsed
var currentDate = new GlideDateTime();
var currentDateStr = currentDate.toString(); // Convert to string for gs.dateDiff
var elapsedSeconds = gs.dateDiff(start_date, currentDateStr, true);
if (elapsedSeconds >= timeDifferenceInSeconds / 2) {
outputs.duration_exceeded = 'true';
} else {
outputs.duration_exceeded = 'false';
}
})(inputs, outputs);
I hope this helps resolve the issues with your script.
If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:31 AM
The flow trigger is going to check requested Item Records every hour
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 09:19 AM
Hello @Manny11
The script you've provided has a few small issues, but it can be easily fixed. Below are some key changes to improve the functionality:
- There are inconsistencies in the method names. It should be getNumericValue() instead of getNumericalValue().
- GlideDateTime.subtract() returns a GlideDuration object, and it should be used properly for numerical comparison.
Here's an updated version:
(function execute(inputs, outputs) {
// Inputs
var start_date = inputs.start_date; // Assuming this is a string in "yyyy-MM-dd HH:mm:ss" format
var end_date = inputs.end_date; // Same format as above
// Calculate the time difference in seconds
var timeDifferenceInSeconds = gs.dateDiff(start_date, end_date, true);
// Calculate if 50% of the time has elapsed
var currentDate = new GlideDateTime();
var currentDateStr = currentDate.toString(); // Convert to string for gs.dateDiff
var elapsedSeconds = gs.dateDiff(start_date, currentDateStr, true);
if (elapsedSeconds >= timeDifferenceInSeconds / 2) {
outputs.duration_exceeded = 'true';
} else {
outputs.duration_exceeded = 'false';
}
})(inputs, outputs);
I hope this helps resolve the issues with your script.
If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!
Thank You
Juhi Poddar