New help on changing the variable label text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 05:07 PM
Hello,
I’m using g_form.setLabelOf('Old Phone Number', 'New Phone Number') method to dynamically change the label of a variable. While the label changes successfully on the portal, it doesn't update in the desktop view. Could someone please help?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 03:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 08:22 PM
Hi @Lisa Goldman ,
Looks like it's not a straightforward solution to set a label for catalog items
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0758098
https://servicenowguru.com/ui-scripts-system-ui/modifying-label-form-fields-client-scripts/
I have used these and update the client script as below with isolate script as false
function onChange(control, oldValue, newValue, isLoading) {
var actualLabel = 'Old Phone:';
var tableName = g_form.getTableName();
if (tableName == 'sc_req_item' || tableName == 'sc_task') { //for RITM and SC Task
var stb = Array.from(document.getElementsByClassName('sn-tooltip-basic'))
stb.forEach(function(item) {
var role = item.getAttribute('role');
if (role == 'heading' && item.innerHTML == actualLabel) {
item.innerHTML = 'New Phone';
}
});
return;
}
try { //for native UI
var labelElement = $('label_' + g_form.getControl('old_phone').id);
labelElement.select('.sn-tooltip-basic').forEach(function(elmt) {
if (newValue == 'yes')
elmt.innerHTML = 'New phone';
else
elmt.innerHTML = actualLabel;
});
} catch (e) { //for portal
if (newValue == 'yes')
g_form.setLabelOf('old_phone', 'New phone');
else
g_form.setLabelOf('old_phone', actualLabel);
}
}
I am also attaching the XML of updated version of client script.
import it and try
but at this point it's easier to create/maintain two separate variables for this as this involves DOM manipulation which is not recommended and might break with future releases.
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 07:05 AM
I'm assuming you checked to make sure that the client script is set to run on the Item and cat task correct?
Also have you checked the browser console to see if there is an error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 03:18 PM
Hi @DrewW
The issue I'm encountering is with the Item and Catalog Task in the fulfiller view.
It works perfectly fine in the self-service portal without any errors.
Below are the steps I tested in my PDI. When you have a chance, you can replicate it in your PDI to check if you're experiencing the same issue.
STEP 1 - Create a text variable
STEP 2 - Create a Multiple choice variable with one value "yes"
STEP 3 - onChange Client Script code:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == 'yes') {
g_form.setLabelOf('old_phone', 'New Phone');
} else {
g_form.setLabelOf('old_phone', 'Old Phone');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 03:34 PM
Attached in an update set if you would like to try it in your PDI. Thank you