passing date values to rest api from scheduled job

samadam
Kilo Sage

I am trying to pass date values using setStringParameterNoEscape() but doesnt see to be taking the dates.

setStringParameterNoEscape('fromDate', yesterday);

I have the right dates when I print to logs. Is there something specific that needs to be done for date values.

6 REPLIES 6

Omkar Mone
Mega Sage

Hello,

 

Can you help us with the code?

 

 

samadam
Kilo Sage
var today = new GlideDateTime();
    var curDate = today.getDate();
    today.addDaysUTC(-1);
    var yesterday = new GlideDate();
    yesterday.setValue(today.getDate());
var r = new sn_ws.RESTMessageV2('TEST', 'GET');
    r.setStringParameterNoEscape('fromDate', yesterday);
    r.setStringParameterNoEscape('toDate', yesterday);
    r.setEccParameter('skip_sensor', true);
    var response = r.execute();
when i run this, this is getting all the records instead of just that are updated yesterday..

@samadam 

 

Below posts are some what similar to requirement. You can try the approach suggested -

https://www.servicenow.com/community/now-platform-forum/how-do-i-specify-date-time-range-in-rest-get...

https://www.servicenow.com/community/developer-forum/want-to-pass-date-time-parameter-in-a-rest-mess...

 

Also, I can see you are passing yesterday variable to both from and to date parameter. Please check on that.

Thanks and Regards
Amit Verma

Have you created the query param?