How to append text to the value entered on variable?

Ashwini Jadhao
Giga Guru

I have a variables called Department and Sub Department.The requirement is append .sub  to the value entered on Department. It should be on form load.

Eg Department is Computer then Sub Department should be Computer.sub

I have written script as below but it is not working.It shows undefined.

function onLoad() {
var control = g_form.getControl('department');
var tm = control+'.sub';
control.onkeyup = myCustomFunction; 

function myCustomFunction() {
g_form.setValue('subDepartment', tm.value);
}
}

1 ACCEPTED SOLUTION

Hi,

can you alert the value of department; is the field name correct?

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}

if(newValue == '')
g_form.clearValue('sub_department');

var abc = g_form.getValue('department');

alert('department is: ' + abc);

g_form.setValue('sub_department', abc + '.sub');

Regards

Ankur

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

View solution in original post

11 REPLIES 11

Tanushree Doiph
Mega Guru

Hey,

Try this code, 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var abc= g_form.getValue('department');

g_form.setValue('sub_department', abc+ ' ' + .sub+);

Thanks

Tanushree

Hi Tanushree,

getDisplayValue() won't work in client side scripts

Regards

Ankur

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

Hi Ankur,

It was my silly mistake, thanks for repairing it.

Thanks

Tanushree

No worries.

Regards

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