Compare Due date with Current Date

Sironi
Kilo Sage

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);
}
}
}

 

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

Mike Patel
Tera Sage

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();
    }
}

Hi Mike,

Your Code working Great..!

Due date is only Date type field

find_real_file.png

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);
}
}
}

Yes, you can use that format. Is your u_date_to_invoice field Date/Time and how are you running this script?