- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 02:30 AM
Hi All,
I have a requirement where i need to check whether there is an attachment added to a record for the current update.
I am using the below script to check on that
var time = new GlideDateTime(gs.minutesAgo(-2)).getDisplayValue();
var inc = new GlideRecord("sys_attachment");
inc.addQuery("table_name", "incident");
inc.addQuery('sys_created_on', '>' , time);
inc.query();
if(inc.next())
{
gs.print("Test" +time );
}
else
{
gs.print("Test Failed");
}
even if there is any attachment added in last two minutes . I am running this script on back ground. Even if the condition inc.addQuery('sys_created_on', '>' , time); doesnt meet then also it is printing "Test" +time. Can you point the error in the above .
Thanks
Swathi Padighar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 03:00 AM
I think you should change to:
var time = new GlideDateTime(gs.minutesAgo(2)).getValue();
Minutes ago -2 is minutes in the future, and dont use display value, but internal value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 02:52 AM
Hi,
I did check & it works well. Can you try by adding more of logs something as below to get it checked in detail.
var time = new GlideDateTime(gs.minutesAgo(-2)).getDisplayValue();
//gs.print('time is '+time);
var inc = new GlideRecord("sys_attachment");
inc.addQuery("table_name", "incident");
inc.addQuery('sys_created_on', '>' , time);
inc.query();
if(inc.next())
{
gs.print('Created on '+inc.sys_created_on);
gs.print("Test" +time );
gs.print('time is '+time);
}
else
{
gs.print("Test Failed");
}
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 03:00 AM
I think you should change to:
var time = new GlideDateTime(gs.minutesAgo(2)).getValue();
Minutes ago -2 is minutes in the future, and dont use display value, but internal value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 05:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 06:00 AM
minutesAgo substracts the value, so -2 is a double negative so 2 minutes will be added.
gs.minutesAgo(2) //"2018-03-14 12:56:37"
gs.minutesAgo(-2) //"2018-03-14 13:00:37"