- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 09:06 AM
How can I run an onBefore transform script to convert mm-dd-yyyy hh:mm:ss to yyyy-dd-mm ? I attempted to use target.u_install_date = new GlideDateTime(source.u_asset_start_date) but it continued to show an error
I've also tried: target.u_install_date = source.u_asset_start_date.getByFormat("yyyy-mm-dd")
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 10:55 AM
Hi Joseph,
So incoming value is date/time and target field is date field; but the format is different try this script and let me know if that works
var dateTime = source.u_asset_start_date;
var gdt = new GlideDateTime(dateTime);
var year = gdt.getYearUTC();
var month = gdt.getMonthUTC();
var day = gdt.getDayOfMonthUTC();
var finalDate = year + '-' + day + '-' + month;
target.u_install_date = finalDate;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 10:55 AM
Hi Joseph,
So incoming value is date/time and target field is date field; but the format is different try this script and let me know if that works
var dateTime = source.u_asset_start_date;
var gdt = new GlideDateTime(dateTime);
var year = gdt.getYearUTC();
var month = gdt.getMonthUTC();
var day = gdt.getDayOfMonthUTC();
var finalDate = year + '-' + day + '-' + month;
target.u_install_date = finalDate;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 11:45 AM
Worked Thanks!