If end date is prior 3 days or 1 day then trigger an email

Prithvi Ramesh1
Mega Sage

If end date is prior 3 days or 1 day then trigger an email

If Opened date is prior 3 days and still it is un approver then trigger an email

 

Flow configuration:

 

PrithviRamesh1_1-1753013905528.pngPrithviRamesh1_2-1753013920551.pngPrithviRamesh1_3-1753013937130.png

Set Flow Varibale Script:

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/

gs.info("PRITHVI: Starting time difference calculation...");

// Get today's date
var today = new GlideDate();

// Get the end date from the Flow data
var endDate = fd_data._19__for_each.item.variables.end_date;
gs.info("PRITHVI: Retrieved end date = " + endDate);

// Calculate time difference in days between today and end_date
var timediff = gs.dateDiff(today, endDate, true) / 60 / 60 / 24;
gs.info("PRITHVI: Calculated time difference in days = " + timediff);

// Check if the time difference is exactly 1 or 3 days
if (timediff == 3 || timediff == 1) {
    gs.info("PRITHVI: Time difference matches allowed values (1 or 3). Returning: " + timediff);
    return true;
} else {
    gs.info("PRITHVI: Time difference does not match allowed values. Returning: 'None'");
    return false;
}

 

PrithviRamesh1_4-1753013983085.png

 

PrithviRamesh1_5-1753014004649.pngPrithviRamesh1_6-1753014015500.pngPrithviRamesh1_7-1753014027321.png

 

Flow Variable Code:

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/

gs.info("PRITHVI: Starting time difference calculation...");

// Get today's date
var today = new GlideDate();

// Get the end date from the Flow data
var endDate = fd_data._25__for_each.item.opened_at;
var gdt = new GlideDate(endDate);
gs.info("PRITHVI: Retrieved end date = " + gdt);

// Calculate time difference in days between today and end_date
var timediff = gs.dateDiff(today, gdt, true) / 60 / 60 / 24;
gs.info("PRITHVI: Calculated time difference in days = " + timediff);

// Check if the time difference is exactly 1 or 3 days
if (timediff == 3) {
    gs.info("PRITHVI: Time difference matches allowed values (1 or 3). Returning: " + timediff);
    return true;
} else {
    gs.info("PRITHVI: Time difference does not match allowed values. Returning: 'None'");
    return false;
}

 

 

4 REPLIES 4

GlideFather
Tera Patron

Hi @Prithvi Ramesh1 

is this a question or knowledge sharing?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hi @GlideFather 

 

This is a question

@Prithvi Ramesh1 
ok, I don’t see any configurations on the  date verification.

 

for that either a separate flow or scheduled job would be required, either one option shall be triggered daily in early morning or late night hours

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Nishant8
Giga Sage

Hello @Prithvi Ramesh1 , could you try to move Get Catalog Variables action to position 20 and then try to set the variable in position 21. also, modify the script as following

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/

gs.info("PRITHVI: Starting time difference calculation...");

// Get today's date
var today = new GlideDate();

// Get the end date from the Flow data
var endDate = fd_data._20__get_catalog_variables.start_date;
gs.info("PRITHVI: Retrieved end date = " + endDate);

// Calculate time difference in days between today and end_date
var timediff = gs.dateDiff(today, endDate, true) / 60 / 60 / 24;
gs.info("PRITHVI: Calculated time difference in days = " + timediff);

// Check if the time difference is exactly 1 or 3 days
if (timediff == 3 || timediff == 1) {
    gs.info("PRITHVI: Time difference matches allowed values (1 or 3). Returning: " + timediff);
    return true;
} else {
    gs.info("PRITHVI: Time difference does not match allowed values. Returning: 'None'");
    return false;
}

 

Regards,

Nishant