Need to set date value through transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 11:43 PM
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.
Please help.
Thanks all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 12:15 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 12:56 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 02:09 AM - edited 09-20-2024 02:44 AM
i tested it working below logic
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 02:35 AM
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');
}
}