How to copy value of one variable field to another variable field using client script onSubmit

psyherin
Kilo Sage

Hi all,

I am new to scripting and trying to get my head around with this. I am trying to copy single line text variable value available on the form to another single line text variable value which is only visible in VEditor. Below is the Client script with type onSubmit but it doesn't seem to work. 

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var businessPhone = g_form.getValue('business_phone');
   var testPhone = g_form.getValue('test_phone');
		
	if (testPhone =='');
	g_form.setValue('test_phone', businessPhone);
	
}

 

find_real_file.png

I will be extending this script to include multiple single line text variables and copy them to another single line text variables so onChange might not work as i would have to create multiple scripts.

Please let me know how can I go about this.

Thank you

 

1 ACCEPTED SOLUTION

Hi @Ankur Bawiskar ,

I used the onSubmit script and it did update the another single line text variables.

 

find_real_file.png

Is that a good solution ?

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

don't use onSubmit

Please use workflow run script to set the other variable

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

is there any other way instead of using workflow ? i would ideally like to use catalog client scripts

then why not use onChange client script on the business phone variable

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

I used the onSubmit script and it did update the another single line text variables.

 

find_real_file.png

Is that a good solution ?