Want to pass date /time parameter in a REST message

Mrman
Tera Guru

Hi All,

I am creating a REST message with GET method for getting CI details from 3rd party   tool. We need to pass a parameter called "CHANGEDATE" while sending the GET method .

" Change date for list of Configuration Items to be returned (for example records modified in last 3 days). If value is empty, all Configuration Item records are returned. "

After Creating REST Message I am calling it from a scheduled job as we need to query on daily basis . Now the requirement is to pass the current date and time for below( Marked in Green) in script . Please Guide.

try {
var r = new sn_ws.RESTMessageV2('name_of_outbound_rest_message', 'get');
r.setStringParameter('CHANGEDATE', 'currentDateTIme'); =============================> Please Guide how to give Current date and time here .
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

1 ACCEPTED SOLUTION

Shiva Thomas
Kilo Sage

Hi Ravishankar,



You should try this...



gs.nowNoTZ()


It returns the current UTC date time. Ex: 2017-05-31 09:21:19



Source: GlideSystem Date and Time Functions - ServiceNow Wiki


View solution in original post

5 REPLIES 5

swati38
Tera Expert

HI Ravi,



The method gs.nowDateTime()(GMT) or gs.now() will work.



thanks,


Swati


Shiva Thomas
Kilo Sage

Hi Ravishankar,



You should try this...



gs.nowNoTZ()


It returns the current UTC date time. Ex: 2017-05-31 09:21:19



Source: GlideSystem Date and Time Functions - ServiceNow Wiki


Hi Shiva,



Please guide whether this is correct .



try {
var r = new sn_ws.RESTMessageV2('name_of_outbound_rest_message', 'get');


var dtt = gs.nowNoTZ()
r.setStringParameter('CHANGEDATE', dtt); =============================> Please Guide how to give Current date and time here .
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();



Just to be sure I would add a toString to cast your parameter



r.setStringParameter('CHANGEDATE', gs.nowNoTZ().toString() );