
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 10:58 AM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 09:17 AM
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');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 02:51 PM
Did you try this code?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getDisplayBox('u_fac_building');
if(location.startsWith("0152")){
g_form.setValue('assigned_to','');
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 11:10 AM
SN Emy,
Can you provide more details into your requirement? I instinctively want to suggest the indexOf() function rather than startsWith() in the client.
Thanks,
Derrick Johnson

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 12:39 PM
below is my script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getReference('u_fac_building');'
if(location.startsWith("0152")){
g_form.setValue('assigned_to','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:00 PM
SN Emy,
Because this is an On-Change client script, we can simplify the script like so:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue.startsWith('0152')) {
g_form.setValue('assigned_to','');
}
}
Basically, this script clears the 'assigned_to' value when the value of the location field starts with 0152. We do not need to assign the value of u_fac_building to a variable because the script will be listening for changes to this field while the form is loaded.
Thanks,
Derrick Johnson

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2019 01:14 PM
Since location is a reference field, you can try
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var location = g_form.getDisplayBox('u_fac_building');
if(location.startsWith("0152")){
g_form.setValue('assigned_to','');
}
}
Please mark this response as correct or helpful if it assisted you with your question.