How to copy date from date/time field to another date field (on form)?

jas101
Tera Expert

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.

find_real_file.png

 

16 REPLIES 16

Harsh Vardhan
Giga Patron

Jaspal Singh
Mega Patron
Mega Patron

You can use g_form.getReference()  used in onLoadclient script that works on load of Change form that has CAB field

 

function onLoad() {
   //Type appropriate comment here, and begin script below
 var chkcabdate=g_form.getReference('cab_meet',chkdate); //consdering cab_meet is custom field that refers CAB meeting table
	
	function chkdate(chkcabdate){
		g_form.setValue('u_cab_meeting',chkcabdate.u_meeting_date); //considering u_cab_meeting is the field on Change form where date is to be set 
	}
	
}

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Hi, thanks for the update - would this work/set the date once the user has chosen their 'CAB meeting' value though or only after a form re-load? We ideally want 'CAB date' to set on update/change of the 'CAB meeting' value.

I have updated your onLoad script as per below, substituting in correct field/table names however please note the CAB meeting.Start field is a date/time field and 'CAB date' is a date field (not date/time) so I don't think it currently accounts for this?

Currently I am now just seeing 'undefined' in the 'CAB date' field on the change form.

function onLoad() {
//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
}

}

In that case you need to use onChange client script which would run on change of CAB Meeting field.

replace the first line of function onLoad() to 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

while rest remains the same.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.