Compare Due date with Current Date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 10:57 AM
Hi,
Can some one help me my script is correct or Not
How to Compare Due date with Current Date, if both dates match then set field value.
billinglineitems();
function billinglineitems() {
var gr = new GlideRecord('u_billing_milestone');
gr.addQuery('u_date_to_invoiceISNOTEMPTY');
gr.addQuery('u_state!=Ready for Invoice');
gr.query();
while (gr.next())
{
var now = gs.now();
if (now == gr.u_date_to_invoice)
{
gs.info("yes Matched :" + gr.u_number);
gr.u_state = 'Ready for Invoice';
gr.update();
}
else
{
gs.info("no Matched :" + gr.u_number);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 11:00 AM
Use below blog for date validations
https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 11:00 AM
try below. As long as due date is date/time format and has exactly value as now.
billinglineitems();
function billinglineitems() {
var now = gs.now();
var gr = new GlideRecord('u_billing_milestone');
gr.addQuery('u_date_to_invoiceISNOTEMPTY');
gr.addQuery('u_state!=Ready for Invoice');
gr.addQuery('u_date_to_invoice', now);
gr.query();
while (gr.next()) {
gr.u_state = 'Ready for Invoice';
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 11:14 AM
Hi Mike,
Your Code working Great..!
Due date is only Date type field
can i use below format also?.......
function billinglineitems() {
var gr = new GlideRecord('u_billing_milestone');
gr.addQuery('u_date_to_invoiceISNOTEMPTY');
gr.addQuery('u_state!=Ready for Invoice');
gr.query();
while (gr.next())
{
var now = gs.now();
if (now == gr.u_date_to_invoice)
{
gs.info("yes Matched :" + gr.u_number);
gr.u_state = 'Ready for Invoice';
gr.update();
}
else
{
gs.info("no Matched :" + gr.u_number);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 11:24 AM
Yes, you can use that format. Is your u_date_to_invoice field Date/Time and how are you running this script?