- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2018 05:44 PM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 12:54 PM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 12:54 PM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 06:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2018 02:44 AM
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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 09:32 PM
Hi,
In your business rule, You have to compare the current date with created date of a record using gs.dateDiff.