Dynamic label on catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have written onchange client script where I am setting the label of a variable on runtime. based on the other variable selection . But in RITM it is still showing old label name. Please advise on this .
NOTE:
- RITM displays variable names and labels based on the variable definition in the catalog item, not the dynamic label applied during form rendering.
- g_form.setLabelOf() updates the UI only for the current session; it does not persist the label to the variable’s value or metadata.
My Script:function onChange(control, oldValue, newValue, isLoading) {if (isLoading || newValue == '') return;var sourceValue = g_form.getValue('source_field');var labelText = '';if (sourceValue == 'AAA') {labelText = 'XXX';} else if (sourceValue == 'BBB') {labelText = 'YYY';} else {labelText = 'ZZZ';}// ✅ Smooth label updatesetTimeout(function() {g_form.setLabelOf('source_data', labelText);}, 300);}
O/p:
on RITM it is still showing label name "source_data"
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi, you should set the field "Applies on Requested Items" on your Catalog Client Script to true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
2 things to perform and then verify
1) ensure your catalog client script runs on RITM as well. Mark "Applies on Requested Item" as True
2) also update your script as this -> remove isLoading check so that your onchange runs when form loads as well
function onChange(control, oldValue, newValue, isLoading) {
var sourceValue = g_form.getValue('source_field');
var labelText = '';
if (sourceValue == 'AAA') {
labelText = 'XXX';
} else if (sourceValue == 'BBB') {
labelText = 'YYY';
} else {
labelText = 'ZZZ';
}
// :white_heavy_check_mark: Smooth label update
setTimeout(function() {
g_form.setLabelOf('source_data', labelText);
}, 300);
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
