I need to use startsWith() function on a client script, but I got an error

SN Emy
Tera Guru

Hi,

I need to use startsWith() function on a client script, but I got this error.

           onChange script error: TypeError: location.startsWith is not a function function () { [native code] }

 

please help?

 

1 ACCEPTED SOLUTION

SN Emy
Tera Guru

I fixed it, I have to add .name to the location.

Than you all.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getReference('u_fac_building');
//g_form.addInfoMessage(location.name);

if(location.name.substring(0,4) == "0152"){

g_form.setValue('assigned_to','442d90fa4f4f8b003aeb58211310c784');


}
}

View solution in original post

13 REPLIES 13

Gary Fawcett
Kilo Contributor

Since you only want to know about the start of the string "indexof" won't work, but substring should.

 

How about this:-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getReference('u_fac_building');'
if(location.substring(0,4) == "0152"){
g_form.setValue('assigned_to','');
}
}

Thanks...Gary

Thanks Gary,

I got the same error event with substring

onChange script error: TypeError: location.substring is not a function function () { [native code] }

 

 

find_real_file.png

SN Emy
Tera Guru

I fixed it, I have to add .name to the location.

Than you all.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getReference('u_fac_building');
//g_form.addInfoMessage(location.name);

if(location.name.substring(0,4) == "0152"){

g_form.setValue('assigned_to','442d90fa4f4f8b003aeb58211310c784');


}
}

dimple adlakha
Tera Contributor

What is "name" define here , i have same requirement where the field is refrence type and it has numeric number . i want if the field starts with number 12 then it will populate error message