How to copy date from date/time field to another date field (on form)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2018 04:59 AM
Hi guys, on our change form what is the best way for us to populate field 'CAB date' (a date field) with the date from the 'Meeting start time' (a date/time field) that is selected by our user on a custom field 'CAB meeting' (which references table 'Cab meeting') - see below of screenshot of CAB meeting look-up example.
So we want to take the date from 'Meeting start time' and populate our 'CAB date' field with this.
Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 06:56 AM
Ah OK thanks, I guess I just thought we could get the date format showing as our system date format is dd/MMM/yyyy (my date format is set to system also) - and as the meeting start time appears as this date format in the 'CAB meeting' look-up I just wondered what's causing it to go as '2018-08-15' (i.e. US date format) when setting the CAB date field.
I tried with the updated onChange client script which I see has getDisplayValue but alas now no CAB date is being set unfortunately.
If you don't think it's viable I think I'll ask the powers that be to rethink this requirement. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 07:06 AM
Hang on sorry... I didn't realise that if saving the record with this 'US' format in the CAB date field, it would still then save as a 'valid' value and show as expected on next form load. Hmm this may be OK although if we could get the getDisplayValue bit working so it appears in the system date format initially that would be terrific!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 07:07 AM
If you save the change, does the format change to your system/user format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 07:17 AM
Yes indeed sorry, that what's I meant in my update message just before you posted your last oe - to me the value in the CAB date field was just looking like an 'invalid' one but upon saving the record it's recognised and the format appears in the system one, great!
Do you think there is a way of making the initial value show as this format (dd/MMM/yyyy) - like attempted with the getDisplayValue version of the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 07:59 AM
Dates are very tricky client side and there are a few threads like this one that describe options:
https://www.servicenowguru.com/scripting/client-scripts-scripting/client-side-dates-in-servicenow/
However even this article notes:
One thing to keep in mind with this, depending on where the date is coming from you may still have two date formats. Any of the dates that will work as shown are going to be the values in fields on a form or the Display Value of the date. If you’re getting something from the server (e.g. via GlideAjax) as just a value then it will be stored in the regular system format of YYYY-MM-DD HH:MM:SS.
Another option is to set the Cab date server side via a business rule and let the users know it will be set on save which will then show up in the right format.