- 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:41 PM
I actually did try to find OOB examples and saw some weird stuff. One script I saw setLabelOf used the regular way I did:
g_form.setLabelOf("target_entity_instance_id", "Blueprint");
but also like this:
g_form.setLabelOf("target_entity_instance_id", getMessage("Cloud Resource"));
Both ways in the same onChange client script, didn't know what to make of that.
In another OOB onChange client script I saw it being used like this:
// checking support of setLabel api for workspace
var changeLabel = g_form.setLabel;
if (!changeLabel)
changeLabel = g_form.setLabelOf.bind(g_form);
else
changeLabel = g_form.setLabel.bind(g_form);
if (g_form.getValue('resolution_code') === '') {
if (g_form.hasField('closed_at'))
changeLabel('closed_at', getMessage("Closed"));
}
but even the OOB code doesn't actually dynamically change the field labels whenever the onChange field changes.
- 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
‎04-01-2021 03:33 AM
Hii i am also getting the same error.where do i find the SN utiils browser plugin? and how to change the setting of "show technical names on page load"
Anybody please let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2021 11:26 AM
Hi Daniel,
Where is this setting found?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2021 06:04 PM
SN utils is a Chrome browser extension you can get from the Google Chrome store.