Exclude time while running background script in Servicenow

rashmin3
Tera Contributor

Hi 

 

I have a requirement to run background script on demand form. if demand is having contract then contract created date should populate on Actual won date on demand form, I have written background script but here the issue is Contract creted field is Date/Time type and Actaula won date is only Date field so it is updating one day before the contract created date, so I need to exclude the time from contract created date.

 

any idea how can we achiev this - below is my code it is working for updating the records but need to exclude the time from contract created date.

 

var dmn = new GlideRecord('dmn_demand');
dmn.addEncodedQuery(' ');
dmn.query();

while (dmn.next()) {
    var contract = new GlideRecord('ast_contract');
    contract.addQuery('u_demand', dmn.getUniqueValue());
    contract.addQuery('u_contract_type', 'Parent');
    contract.query();

    if (contract.next()) {
        dmn.u_actual_won_date = contract.sys_created_on;
        dmn.setWorkflow(false);
        dmn.update();
       }
}
       
    Best Regards,

 
1 REPLY 1

Sanjay191
Tera Sage

Hello @rashmin3 

Please try the below code if any thing else please ping me and i hope this will work

var dmn = new GlideRecord('dmn_demand');
dmn.addEncodedQuery(' ');
dmn.query();

while (dmn.next()) {
    var contract = new GlideRecord('ast_contract');
    contract.addQuery('u_demand', dmn.getUniqueValue());
    contract.addQuery('u_contract_type', 'Parent');
    contract.query();

    if (contract.next()) {
        var contractdateTime = new GlideDateTime(contract.sys_created_on);
        var contractDate = contractdateTime.getDate();
        dmn.u_actual_won_date = contractDate;
        dmn.setWorkflow(false);
        dmn.update();
}


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank You