In a business rule how do you check to see if the created record is 30 days old?

drewmleynek
Giga Contributor

I have a table that populates with inactive users. I have an auto script running daily that triggers a business rule. When a user is inserted into that table I want to have a business rule check that record and see if it has passed 30 days since it was originally created. I am not sure how to go about this. Any help would be appreciated.

 

Thank you!

1 ACCEPTED SOLUTION

ARG645
Tera Guru

In your business rule use the below Logic to compare if the record has passed 30 days after creation. I have also included Hours and Minutes, just in case if you want to compare using Hours. 

 

var createdOn = current.sys_created_on;
var now = new GlideDateTime();
var gdt1 = new GlideDateTime(createdOn);

var miliseconds= GlideDateTime.subtract(gdt1, now).getNumericValue(); 

var total_seconds = parseInt(Math.floor(miliseconds / 1000));
var total_minutes = parseInt(Math.floor(total_seconds / 60));
var total_hours = parseInt(Math.floor(total_minutes / 60));
var days = parseInt(Math.floor(total_hours / 24));

if(days > 30)
{
  //Add your Code here
}

View solution in original post

4 REPLIES 4

ARG645
Tera Guru

In your business rule use the below Logic to compare if the record has passed 30 days after creation. I have also included Hours and Minutes, just in case if you want to compare using Hours. 

 

var createdOn = current.sys_created_on;
var now = new GlideDateTime();
var gdt1 = new GlideDateTime(createdOn);

var miliseconds= GlideDateTime.subtract(gdt1, now).getNumericValue(); 

var total_seconds = parseInt(Math.floor(miliseconds / 1000));
var total_minutes = parseInt(Math.floor(total_seconds / 60));
var total_hours = parseInt(Math.floor(total_minutes / 60));
var days = parseInt(Math.floor(total_hours / 24));

if(days > 30)
{
  //Add your Code here
}

Chris Sanford1
Kilo Guru

You can use the one liner 'current.sys_created_on < gs.daysAgo(-30);'.

However, you say 'When a user is inserted into that table' do you mean updated? When a user is inserted into that table, it will always be 0 days since it was initially created.

gs.daysAgo(-30) will give the future date after 30 days. Change the parameter to just 30.

By the way 'current.sys_created_on < gs.daysAgo(30);'  can be used, but better avoid comparing an Object to a String. gs.daysAgo will output a String and current.sys_created_on is an Object. 

It can be done by converting gs.daysAgo to a GlideDateTime Object

var past = new GlideDateTime(gs.daysAgo(30));
var result = current.sys_created_on < past;

SaiRaviKiran Ak
Giga Guru

Hi,

 

In your business rule, You have to compare the current date with created date of a record using gs.dateDiff.