- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 01:07 PM
I'm trying to use g_form.setLabelOf in an onChange client script on the default Problem form. Here is my very simple code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue == 'software'){
g_form.setLabelOf('short_description', 'Problem Statement');
g_form.setLabelOf('description', 'What is current state?');
g_form.showFieldMsg('short_description', 'should have changed to PS', 'info');
}
else{
g_form.setLabelOf('short_description', 'still Short description');
g_form.setLabelOf('description', 'still Description');
g_form.showFieldMsg('short_description', 'should have changed to SD', 'info');
}
}
The field is the OOB "category" field. The showFieldMsg calls are just to check that the code is making it to those points, which it is. None of the setLabelOf calls work. When I run setLabelOf in my browser console it also doesn't work and returns false. If I put a nonexistent field into the fieldname variable of setLabelOf then I get an error field-message:
onChange script error: TypeError: Cannot read property 'id' of undefined function () { [native code] }
Am I doing something wrong? Shouldn't setLabelOf work dynamically without saving or reloading the form?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 03:35 PM
Figured it out, the issue is caused by the SN Utils browser plugin. setLabelOf doesn't change the labels dynamically when the SN Util "Show Technical names on page load" setting is on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 02:01 PM
Something is up with your showFieldMsg statement, as this works just fine IF I comment out the showFieldMsg statement. A good practice I learned is to look at out of the box examples and I found several client scripts using setLabelOf() so I knew it should work hence why I started commenting out the extra pieces of your code and realized it is not setLabelOf and its showFieldMsg().
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 'software') {
g_form.setLabelOf('short_description', 'Problem Statement');
g_form.setLabelOf('description', 'What is current state?');
// g_form.showFieldMsg('short_description', 'should have changed to PS', 'info');
} else {
g_form.setLabelOf('short_description', 'still Short description');
g_form.setLabelOf('description', 'still Description');
//g_form.showFieldMsg('short_description', 'should have changed to SD', 'info');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 02:17 PM
It still doesn't work for me if I comment out showFieldMsg. Tried in my business dev on Madrid and my PDI on New York.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 02:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 02:44 PM
Just to clarify, the field label changes immediately when you change the "Category" dropdown selection, without saving?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2019 02:50 PM
Wow when I tried it on Internet Explorer it actually works. Not sure how helpful this is though because I'm pretty sure most of the users will be on the same version of Chrome I'm on, where I can't get it to work.