Need assistance with script?

Community Alums
Not applicable
 
1 ACCEPTED SOLUTION

Harsh_Deep
Giga Sage
Giga Sage

Hello @Community Alums 

 

Why you have deleted your query and after accepting my solution why you have removed that, Can you please explain.

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

View solution in original post

9 REPLIES 9

piyushsain
Tera Guru
Tera Guru

Hi,

Use below script 

var date= new GlideDateTime(source.u_last_contact);
date = date.getByFormat('yyyy-mm-dd HH:mm:ss');

 

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

Community Alums
Not applicable

Hi @piyushsain , How to handle two different format which are coming from source?

Hi @Community Alums 

Whatever may be the source format if you use above code it will change the format to the required format

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

Harsh_Deep
Giga Sage
Giga Sage

Hello @Community Alums 

 

Use this -

answer = (function transformEntry(source) {
    var gdt = new GlideDateTime();
    var parsedDate = new Date(source.u_last_contact);
    if (!isNaN(parsedDate.getTime())) {
        // Format the date as 'yyyy-MM-dd HH:mm:ss'
        var formattedDate = parsedDate.toISOString().replace(/T/, ' ').replace(/\..+/, '');
        return formattedDate;
    }
    else{
        return source.u_last_contact;
    }
})(source);

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.