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 04:31 AM
Thanks, I have updated it to an onChange script as per below but I still don't think it's accounting for the fact one of the fields is a date/time field and one is a date field? I am currently now seeing no value in the 'CAB date' date field when I select a value on the 'CAB meeting' date/time field.
Thank-you.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var chkcabdate=g_form.getReference('u_cab_meeting',chkdate); //u_cab_meeting is a date/time field - we want the date from this to set the cab_date field
function chkdate(chkcabdate){
g_form.setValue('cab_date',chkcabdate.start); //'start' is the field for 'Meeting start time' on the cab_meeting table
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 06:21 AM
Try the following script. I changed the getReference call to user a function instead to make it better compatible with mobile and Service Portal. You will notice I split the date time based on the space and set the first portion (date) to your cab_date field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('u_cab_meeting', function(gr) {
var startDateTime = gr.start.toString();
var startDate = startDateTime.split(" ")[0];
g_form.setValue('cab_date', startDate);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 06:34 AM
Thanks Michael. So the good news is the 'CAB date' field is now auto-populating on change of 'CAB meeting', however the format - which I should have mentioned prior - is not as the CAB date field wants it (e.g. '25/Jul/2018').
So e.g. upon choosing the 'CAB meeting' record with a meeting start time of '15/Aug/2018 14:00:00' it is populating CAB date as '2018-08-15'. Can this be rectified via the client script? Thank-you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 06:41 AM
Format is a system setting with the ability for a user to override. The dates are all stored the same and in UTC timezone the database and then format/timezone is changed based on setting/preference on display. So there is no way to set a format for one field over another via script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 06:43 AM
You could try this to see if maybe it helps as it will get the date in the current user's format:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('u_cab_meeting', function(gr) {
var startDateTime = gr.start.getDisplayValue().toString();
var startDate = startDateTime.split(" ")[0];
g_form.setValue('cab_date', startDate);
});
}