The CreatorCon Call for Content is officially open! Get started here.

Need to set date value through transform map

varma2
Mega Sage

Hi All,

 

we are receiving data through Transform map from excel To alm_hardware table. we have a field called Purchased ( Target field)  and field type  is ( glide_data) format is "yyyy/mm/dd" .

But in Source field ( Invoice_data)  we receiving Date format is  ''dd/mm/yyyy/''.  i have tried different method but date value not fetching to target field.

 

varma2_0-1726814434469.png

 

Please help.

 

Thanks all.

 

 

4 REPLIES 4

SP22
Giga Sage

Hello @varma2,

Can you please the below link and let me know whether it is useful or not.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0955636

Thanks
SP.

Rajesh Chopade1
Mega Sage

hi @varma2 

try below script once:

(function transformEntry(source) {
    // Source field format: dd/mm/yyyy
    var sourceDate = source.u_invoice_data; // Replace 'u_invoice_data' with the correct source field name
    
    if (sourceDate) {
        // Split the source date into day, month, and year components
        var dateParts = sourceDate.split('/');
        var day = dateParts[0];
        var month = dateParts[1];
        var year = dateParts[2];

        // Reformat to yyyy/mm/dd
        var formattedDate = year + '/' + month + '/' + day;
        
        // Set the target field with the reformatted date
        target.purchased = formattedDate;
    }
})(source);

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

Mani A
Tera Guru

@varma2 

 

i tested it working below logic

ManiA_0-1726825436231.png

 

 

var invoiceDate = source.u_invoice_data; 
if (invoiceDate) {
var dateParts = invoiceDate.split('/');
if (dateParts.length === 3) {
var formattedDate = dateParts[2] + '/' + dateParts[1] + '/' + dateParts[0];
target.purchased = formattedDate; 
} 

 

aryanjain25
Giga Guru

Hi @varma2 , try the below code snippet:

 

function convertDateFormat(gr) {
    var invoiceDate = gr.getValue('Invoice_data');
    if (invoiceDate) {
        var newDate = new GlideDateTime(invoiceDate);
        newDate.setDisplayValue(invoiceDate, 'yyyy/mm/dd');
    }
}