- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:38 AM
I wanna compare a variable to a system field:
system field - closed (closed_at) type is date/time
variable - Requested end date (requested_end_date) type is date
want the sys_id's of only those tasks(sc_task) where closed date is greater than requested end date (closed > req_end_date)
i am using following code:
var ids = [];
var gr = new GlideRecord('sc_task');
gr.query();
while(gr.next())
{
var gdt1 = new GlideDateTime(gr.closed_at.getDisplayValue());
var requested_end_date = new GlideDateTime(gr.variables.requested_end_date);
//var result = gs.dateDiff(requested_end_date , gdt1,true);
if((requested_end_date != '' || requested_end_date != null ) && requested_end_date < gdt1){
ids.push(gr.sys_id.toString());
}
}
THE ABOVE CODE GIVES ME SYS_IDS EVEN IF CLOSED DATE IS LESS THAN REQ END DATE, WHEREAS IT SHOULD RETURN ONLY THE GREATER ONES.
Any help on this pls
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:57 AM
hi here you can compare both by considering only the date and not time
you just have to slice the time part and take the date part and pass it to datediff method using ajaxcall... this should work..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 01:00 AM
Hi Vineetha,
You can convert date into date format using GlideDateTime object.
var gDate = new GlideDate();
gDate.setValue(requested_end_date);
var gDateTime = new GlideDateTime(gDate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 01:01 AM
Hi Balaji, i got it working now, thank you for your reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 01:07 AM
Hi Vineetha,
Your script should be some thing like below
var ids = [];
var gr = new GlideRecord('sc_task');
gr.query();
while(gr.next())
{
var gDate = new GlideDate();
gDate.setValue(requested_end_date);
var gDateTime = new GlideDateTime(gDate);
var date1 = new GlideDateTime();
var date2 = new GlideDateTime();
date1.setDisplayValueInternal(gDateTime);
date2.setDisplayValueInternal(closed_at);
// Determine the difference as number of seconds (returns a string)
// Use getDisplayValue() to convert the string to the format expected by dateDiff()
var diffSeconds = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), true);
// JavaScript will coerce diffSeconds from a string to a number
// since diffSeconds is being compared to a number
if((requested_end_date != '' || requested_end_date != null ) diffSeconds <= 0) {
gs.print("your message");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 01:12 AM
Hi Vineetha,
Few suggestions here,
var ids = [];
var gr = new GlideRecord('sc_task');
gr.query();
while(gr.next())
{
var gr = new GlideRecord('sc_task');
gr.query();
if(gr.next())
{
var gdt1 = new GlideDateTime(gr.closed_at.getDisplayValue());
var dte= gdt1.getDate();
var requested_end_date= new GlideDateTime(gr.u_follow_up_date.getDisplayValue());
var dte2= requested_end_date.getDate();
var result = gs.dateDiff(dte2, gdt1,true);
if(((requested_end_date != '' || requested_end_date != NULL) && result<0){ // NULL from null and result<0
ids.push(gr.sys_id.toString());
}
}
I think this should work