Giving me error as: {"code":"invalidDateFormat","message":"Invalid date format. Valid date format is

deepikamara
Tera Contributor

Hi,

 

In pre processing script : I am taking current and past 3 days date and passing it in response body as shown in the SS

-------------------------------------------------

(function execute(inputs, outputs) {
var now = new GlideDateTime();
    var threeDaysAgo = new GlideDateTime();
    threeDaysAgo.addDaysUTC(-3);  // Subtract 3 days
    outputs.updatedDateTo = now.getValue().replace(' ', 'T') + 'Z';
    outputs.updatedDateFrom = threeDaysAgo.getValue().replace(' ', 'T') + 'Z';
    gs.info("testing dates::"+typeof(outputs.updatedDateTo)+"::"+typeof(outputs.updatedDateFrom));
})(inputs, outputs);
 Giving me ouput: 2024-11-25T12:11:11Z
 
In Rest step:
---------------------------------------
deepikamara_0-1739276915191.png

 

Giving me error as: {"code":"invalidDateFormat","message":"Invalid date format. Valid date format is YYYY-MM-DDThh:mm:ssZ."}

 

But if i give custom date it is working fine

deepikamara_1-1739277139203.png

Can you please help me here.

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@deepikamara 

what's the format you want to be sent to 3rd party?

Seems your output type for that variable is date/time but you are setting date/time in other format with timezone

Change the output type to String and run once

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

deepikamara_0-1739278575630.png

given but still giving me error  

@deepikamara 

use this and share logs

(function execute(inputs, outputs) {
    var now = new GlideDateTime();
    var threeDaysAgo = new GlideDateTime();
    threeDaysAgo.addDaysUTC(-3); // Subtract 3 days
    var dateTo = now.getValue().replace(' ', 'T') + 'Z';
    outputs.updatedDateTo = dateTo;
    var dateFrom = threeDaysAgo.getValue().replace(' ', 'T') + 'Z';
    outputs.updatedDateFrom = dateFrom;
    gs.info('date to' + dateTo + ' dateFrom ' + dateFrom);
})(inputs, outputs);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

These are the logs date to2025-02-11T13:46:42Z dateFrom 2025-02-08T13:46:42Z