- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 03:50 AM
Hi All
I have a date that I'm reading in from an email input, stripping the rest of the email from around it and trimming out spaces. Cecause the date has come from an email it is in string format and I have placed the output from the trim etc in to a string field (New Contractor End Date Text field in the screen shot below). As its from a user input it could be in any format.
What I need to do is convert that string date in the field New Contractor End Date Text in to an actual date in the right format (ServiceNow format) and output to the field New Contractor End Date.
I've tried a few GlideDate scripts but nothing seems to be working for me. I've also read about Date Parse, but unsure if I need to use that.
Here is my last script:
var date = 'new_cont_end_date_text';
var simpleDateFormat = 'dd-mm-yyyy'; // Simple Date Time format
var gdt = new GlideDate();
gdt.setDisplayValue(date,simpleDateFormat);
gs.addInfoMessage(gdt.getDisplayValue());
u_new_contractor_end_date = setValue.gdt.getDate();
Can someone help me as to where I'm going wrong and am I making this more complicated than it needs to be?
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 08:17 AM
Hi Anita,
yep this makes sense - but still, add to new GlideDateTime("12-12-2020 00:00:00") or it wont be very correct hence prone to errors.
Afterwards, on setting u_new_contractor*** use this format :
current.setDisplayValue('u_new_contractor_end_date', gdt.getDate();
Let me know how it goes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 06:41 AM
Hi Anita,
set the date in the gdt object :
var gdt = new GlideDate("12-12-2020");
also this is wrong:
u_new_contractor_end_date = setValue.gdt.getDate();
should read:
u_new_contractor_end_date.setValue(gdt.getDate());
But first thing first - try the date cast as I suggest and let me know how it goes.
Cheers,
Joro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 07:56 AM
Hi Joro
Thanks for your help. GlideDate gave me an error (java constructor for "com.glide.glideobject.GlideDate" with arguments "string" not found) so I've changed it to GlideDateTime and that has got rid of the error. However I still don't get an output in to my end_date field. I've changed the BR to:
var gdt = new GlideDateTime("12-10-2020");
current.u_new_contractor_end_date.setValue(gdt.getDate());
Thanks
Anita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 08:17 AM
Hi Anita,
yep this makes sense - but still, add to new GlideDateTime("12-12-2020 00:00:00") or it wont be very correct hence prone to errors.
Afterwards, on setting u_new_contractor*** use this format :
current.setDisplayValue('u_new_contractor_end_date', gdt.getDate();
Let me know how it goes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2020 07:05 AM
Hi Joro
I've been playing around with this all day..... it only seems to work as a Display Business Rule, I've tried Before and After and it just leaves the output field blank. However as soon as I change it to Display this works. However that doesn't fulfil what I need to achieve as I need it to do it in the background rather than it wait for the RITM to be displayed.
Thanks
Anita