Skip to content

Commit 02eaef8

Browse files
authored
Check Record Creation was 90 days ago or not and output record age (#2142)
* Create README.md * Create getCIwithmostActiveInc.js * Create README.md * Create checkdateover90.js * README.md * checkdateover90.js
1 parent 5799b94 commit 02eaef8

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Usecase**:
2+
This piece of code can be used to check whether a record was created more than 90 days ago or not.
3+
It returns an output of true/false as well as the actual age (in days) of the record.
4+
5+
**Type**:
6+
Background Script
7+
8+
**How it works**:
9+
There is a pastDateString variable which can contain a date-time which you received by querying any particular record's sys_created_on field or any other relevant field.
10+
In the actual code I have hard-coded a value to be used as an example.
11+
-There are two gliderecord objects to store the current date as well as past date
12+
-GlideDateTime.subtract() is used to calculate the time difference as a GlideDuration object
13+
-The time duration in milliseconds is converted to days by dividing with 86400000(milliseconds in a day)
14+
-Comparison is done between the results
15+
-The final age of the record and true/false result of the comparison is the output.
16+
[Note: Output may vary according to timezones]
17+
18+
**Example**:
19+
pastDateString = 2025-05-01 10:00:00
20+
Output:
21+
22+
Record Age (Days): 165
23+
Older than 90 days? true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//the pastDateString variable can contain a date-time which you received by querying any particular record's sys_created_on field or any other relevant field. Here I'm hard-coding a value.
2+
3+
var pastDateString = '2025-05-01 10:00:00'; //input date and time
4+
var ageThresholdDays = 90;
5+
6+
var gdtPast = new GlideDateTime(pastDateString);
7+
var gdtNow = new GlideDateTime();
8+
var duration = GlideDateTime.subtract(gdtPast, gdtNow);
9+
var durationMs = duration.getNumericValue();
10+
11+
//Calculate the total days (1 day = 86,400,000 milliseconds)
12+
var totalDaysOld = Math.floor(durationMs / 86400000);
13+
14+
var isOlderThanThreshold = false;
15+
if (totalDaysOld > ageThresholdDays) {
16+
isOlderThanThreshold = true;
17+
}
18+
19+
gs.info("Record Age (Days): " + totalDaysOld);
20+
gs.info("Older than " + ageThresholdDays + " days? " + isOlderThanThreshold);

0 commit comments

Comments
 (0)