Create Catalog Task on Selecting Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi All,
I have to create a Catalog task for the Catalog item if the variable "Temporary" is selected, I have created Flow designer for the Catalog item and the Catalog task should create before or less than 14 days (<=14 days) on basis of Temporary date variable selection please suggest what to write script in the Flow Designer. Please check the screenshot attached.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Hi @Dileep2 ,
- Add a 'Get Catalog Variables' action at the beginning of your flow to retrieve the variable values.
- Add an 'If' flow logic block with a condition that checks both requirements. You can do this with a single condition using the Formula builder.
- Check 1: Is the "Temporary" variable selected? (Assuming it's a checkbox or a choice list that can be set to "true" or a similar value).
- Check 2: Is the date difference between the "Temporary" date and today less than or equal to 14 days?
// Check if "Temporary" variable is true AND the temporary date is within 14 days var temporarySelected = fd_data.trigger.current.variables.temporary == 'true';
var temporaryDate = new GlideDateTime(fd_data.trigger.current.variables.temporary_date);
var today = new GlideDateTime();var diff = GlideDateTime.subtract(today, temporaryDate); // returns GlideDuration var daysDiff = diff.getNumericValue() / (1000 * 60 * 60 * 24); // Convert ms to days // Perform the check for temporary selection AND date <= 14 days
(temporarySelected && daysDiff <= 14)
- fd_data.trigger.current.variables.temporary: The data pill for your Temporary variable.
- fd_data.trigger.current.variables.temporary_date: The data pill for your Temporary Date variable.
- Explanation: The script first checks if the Temporary variable is true. If so, it calculates the date difference in milliseconds between the temporary_date and today's date using GlideDateTime.subtract(). It then converts the difference to days and checks if it's less than or equal to 14.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@G Ponsekar please follow below steps, i have tested it in my PDI its working
Flow :
Create a custom action: "Calculate the date difference"
Action script:
(function execute(inputs, outputs) {
var tempDate = inputs.temporary_date;
if (tempDate) {
var temporaryDateTime = new GlideDateTime(tempDate);
var currentDateTime = new GlideDateTime();
// Calculate difference in days
var diff = GlideDateTime.subtract(temporaryDateTime, currentDateTime);
var daysDiff = Math.abs(diff.getNumericValue() / (1000 * 60 * 60 * 24));
outputs.days_difference = daysDiff;
outputs.within_14_days = daysDiff <= 14;
} else {
outputs.within_14_days = false;
}
})(inputs, outputs);
Make sure you create input variables as - temporary_date and output variables as - days_difference and within_14_days