Flow Logic for "If Date At or After Date" not working as expected? Updating null record?

Maurice Murphy
Tera Guru

I'm trying to create automation through which a Flow on a semi-regular basis checks our Server CI's and their Most Recent Discovery. If the Most Recent Discovery is within the last 90 days, make sure the status of the device is all Operational/In Use/etc.

 

The first thing I noticed is that when attempting to create Flow Logic, trying to do a comparison on the date field forced me to utilize a data reference. I wasn't aware that this was a limitation, but I tried to work around it.

MauriceMurphy_0-1720733266013.png

I created a Flow Variable called Last 90 Days and tried to calculate it based on a new GlideDateTime and subtracting 90 days to get the previous 90 days.

 

 

//Get the current date and time as of running this Flow.
var currentDateTime = new GlideDateTime();
//Set a variable 90 days in the past.
var pastDateTime = currentDateTime.addDays(-90);
//Return this variable to the Flow Variable.
return pastDateTime;

 

 

Now, when I set that data reference in and try to test with a handful of records, it doesn't appear to return any date in the Flow logs.

MauriceMurphy_1-1720735075582.png

Finally, it ends up spitting out "Error occurred while updating record: null", even though it does actually return a record.

MauriceMurphy_2-1720735767548.png

I'm not sure if this is being caused by the strangeness with the date, or if it's something else causing this entirely, but any help would be appreciated. Not really sure what's going wrong.

1 ACCEPTED SOLUTION

I'll have to give this a try, but I ended up just giving a scheduled script execution a try. Seems that it has worked out well and does exactly what I need. It's actually slightly simpler because I don't need to do any logic in the script, I can just let the encoded query only include devices I want to update.

 

Code snippet if anyone wants/needs it:

 

// Create a new Glide Record for the CMDB Server table.
var serverCI = new GlideRecord("cmdb_ci_server");
// Add an encoded query for all server CI's discovered at or before
// the last 90 days.
serverCI.addEncodedQuery("last_discovered<=javascript&colon;gs.beginningOfLast90Days()");
// Perform the Glide Query.
serverCI.query();

// Set the Install Status to Retired (7).
serverCI.install_status = 7;
// Set the Operational Status to Retired (6).
serverCI.operational_status = 6;
// Set the Life Cycle Stage to End of Life.
serverCI.life_cycle_stage = "End of Life";
// Set the Life Cycle Stage Status to Retired.
serverCI.life_cycle_stage_status = "Retired";
// Update all records found by the query.
serverCI.updateMultiple();

 

 

View solution in original post

7 REPLIES 7

LearnUseThrive
Mega Sage

Can we see step 2, please? Is the Lookup being done by sysid? That's the best way. 

Shouldn't your condition be At Or After instead of At Or Before?

In this case I believe it should be At or Before Last 90 days, because we want to retire or set as non-operational any device that hasn't been discovered within the last 90 days. We're using After Last 90 days as our reverse condition to catch devices that HAVE been discovered in the last 90 days so we can set them back as operational.

Aishwarya Ghool
Tera Expert

Hi,

 

Can you use below code to get Date/time

 

  var tday = new GlideDateTime();
  var temp = tday;
  temp.addDaysUTC(-90);
  return temp;