- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:51 AM - edited 07-26-2023 07:55 AM
Is it possible to change the question value based on condition?
For example, we've a catalog item wherein multiple variables available like:
-service provider(multiple choice[a,b,c,d]).
-request type(multiple choice--[x,y]).
-account number(single line text)
when service provider is 'b' and request type is 'y', then the variable 'account number' should be changed to 'account ID'(only the question should change).
#itsm #catalog item
There is an option to create 2 variables each for account number and account ID, then use Catalog UI policy based on condition; however, is there any other way to do it without creating multiple variables. I've tried onchange CS with g_form.setLabelof() but isn't helping.
Gurus, please help me with the Catalog CS code..
Thanks in Advance
Solved! Go to Solution.
- Labels:
-
Continual Improvement (CIM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:46 AM
Hello @Snow_Hustler42 ,
Hope you are well!
In the catalog item, when 'Service Provider' is 'b' and 'Request Type' is 'y', dynamically change the label of the 'Account Number' variable to 'Account ID'.
Solution:
1. We have to configure 2 onChange client scripts for the variables 'Service Provider' and 'Request Type' like below.
#onChange Client Script for Service Provider:
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//g_form.addInfoMessage(newValue + "\n" + g_form.getValue('request_type'));
//Type appropriate comment here, and begin script below
if (newValue == 'b' && g_form.getValue('request_type') == 'y') {
g_form.setLabelOf('account_number', 'account ID');
} else {
g_form.setLabelOf('account_number', 'account number');
}
}
# 2 onChange Client Script for 'Request Type':
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
//g_form.addInfoMessage(newValue + "\n" + g_form.getValue('service_provider'));
//Type appropriate comment here, and begin script below
if (newValue == 'y' && g_form.getValue('service_provider') == 'b') {
g_form.setLabelOf('account_number', 'account ID');
} else {
g_form.setLabelOf('account_number', 'account number');
}
}
If this helped you in any way, please hit the like button/mark it helpful. Also, don't forget to accept it as a solution. So it will help others to get the correct solution.
thanks,
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:18 AM
Hi Harshal,
I've tried it and It's changing the label of the account number in the related list i.e., question to account ID in the catalog item. It's not changing the question.name on the form for end user.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:08 AM
Hello @Snow_Hustler42
You can use below script to change label in client script.
g_form.setLabelOf('account_id',"Account Name") ;
where first argument is variable backend name and second argument is new label.
However, I would consider creating new field and showing/hiding that field based on condition using UI policy. This would remove confusion in user while reporting and also easy to mainttain.
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 08:46 AM
Hello @Snow_Hustler42 ,
Hope you are well!
In the catalog item, when 'Service Provider' is 'b' and 'Request Type' is 'y', dynamically change the label of the 'Account Number' variable to 'Account ID'.
Solution:
1. We have to configure 2 onChange client scripts for the variables 'Service Provider' and 'Request Type' like below.
#onChange Client Script for Service Provider:
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//g_form.addInfoMessage(newValue + "\n" + g_form.getValue('request_type'));
//Type appropriate comment here, and begin script below
if (newValue == 'b' && g_form.getValue('request_type') == 'y') {
g_form.setLabelOf('account_number', 'account ID');
} else {
g_form.setLabelOf('account_number', 'account number');
}
}
# 2 onChange Client Script for 'Request Type':
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
//g_form.addInfoMessage(newValue + "\n" + g_form.getValue('service_provider'));
//Type appropriate comment here, and begin script below
if (newValue == 'y' && g_form.getValue('service_provider') == 'b') {
g_form.setLabelOf('account_number', 'account ID');
} else {
g_form.setLabelOf('account_number', 'account number');
}
}
If this helped you in any way, please hit the like button/mark it helpful. Also, don't forget to accept it as a solution. So it will help others to get the correct solution.
thanks,
Prasad