- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2020 11:11 PM
I arranged fields in a form. Based on the choice list, the appropriate fields should be hidden/shown.
Solved! Go to Solution.
- Labels:
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 11:17 PM
Hello Jaichand,
You can do this with UI policy and client script. But if the no. of fields are more and varies based on choice fields, then it can become a lengthy script.
You can make it dynamic like this.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
//make an array of all fields that need to be hidden or shown.
var all_fields = "subcategory,business_service,cmdb_ci,assignment_group,assigned_to";
//Then make a key value of choice value and its associated fields to be hide.
var fields = {};
fields.software = "subcategory,business_service";
fields.hardware = "cmdb_ci";
fields.network = "subcategory,business_service,cmdb_ci";
fields.database = "assignment_group,assigned_to";
//On selection of any choice, first make all fields invisible.
if(newValue!='') {
all_fields = all_fields.split(",");
for(i=0;i<all_fields.length;i++) {
//g_form.setDisplay(all_fields[i],false);
g_form.setVisible(all_fields[i],false);
}
//now show only those fields which are linked to the choice
for(var key in fields) {
if(key == newValue) {
var linked_fields = fields[key].toString();
alert(linked_fields);
linked_fields=linked_fields.split(",");
for(i=0;i<linked_fields.length;i++) {
//g_form.setDisplay(linked_fields[i],true);
g_form.setVisible(linked_fields[i],true);
}
}
}
} else {
//if selection of choice is set to none
all_fields = all_fields.split(",");
for(i=0;i<all_fields.length;i++) {
//g_form.setDisplay(all_fields[i],true);
g_form.setVisible(all_fields[i],true);
}
}
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 01:51 PM
Hi,
This can also be done using UI policy.
To help you i need more information. Can you show what you are talking about
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 11:17 PM
Hello Jaichand,
You can do this with UI policy and client script. But if the no. of fields are more and varies based on choice fields, then it can become a lengthy script.
You can make it dynamic like this.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
//make an array of all fields that need to be hidden or shown.
var all_fields = "subcategory,business_service,cmdb_ci,assignment_group,assigned_to";
//Then make a key value of choice value and its associated fields to be hide.
var fields = {};
fields.software = "subcategory,business_service";
fields.hardware = "cmdb_ci";
fields.network = "subcategory,business_service,cmdb_ci";
fields.database = "assignment_group,assigned_to";
//On selection of any choice, first make all fields invisible.
if(newValue!='') {
all_fields = all_fields.split(",");
for(i=0;i<all_fields.length;i++) {
//g_form.setDisplay(all_fields[i],false);
g_form.setVisible(all_fields[i],false);
}
//now show only those fields which are linked to the choice
for(var key in fields) {
if(key == newValue) {
var linked_fields = fields[key].toString();
alert(linked_fields);
linked_fields=linked_fields.split(",");
for(i=0;i<linked_fields.length;i++) {
//g_form.setDisplay(linked_fields[i],true);
g_form.setVisible(linked_fields[i],true);
}
}
}
} else {
//if selection of choice is set to none
all_fields = all_fields.split(",");
for(i=0;i<all_fields.length;i++) {
//g_form.setDisplay(all_fields[i],true);
g_form.setVisible(all_fields[i],true);
}
}
}
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 11:54 PM
Thank you Asif

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2020 11:51 PM
Hi Jaichand
Service Now Recommends that as part of Best Practice,if you can achieve your Work Using Out of the Box Functionality then Don't go for Scripts.
This is way I am showing you,how you can do this:-
Application Navigator>Open Your Table>Open the Form of Your Table here I have selected the Incident Table
Please Open your Form and Right Click on Banner of Your Form>Configure>UI Policy
Add The Table Name and Select the Field On which you want to perform the Operation.
Now You have to Save the Form not Submit...Do Remember.your form will gets reload.here I have selected the State is on Hold
Perform the Task where choose the Field and and in Mandatory,Visible,Read Only as per your Requirement. in the below Screenshot. Submit the form and check whether it works or Not
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat