restrict choices based on another field in list view

BALAJI K R
Tera Expert

Hi,

 

There 2 fields supplier and product. Product choices are dependent on supplier value, based on the value of the supplier the product choices should be hidden in list view. we can do this in form using onChange client script with add option and clear options. How can we achieve this in list view?

For example:

Supplier fields has supplier A and supplier B

Product has A,B & C

When supplier field is selected as supplier A then product should show A & B

When supplier field is selected as supplier B then product should show B & C

 

Thanks

1 ACCEPTED SOLUTION

@BALAJI K R 

 

Yes, absolutely.

1. Once you have selected the dependent field as "Supplier" in Product dictionary form. 

2. Scroll down to choices and define as many choice you want to make visible based on selection of Supplier as shown below:

shloke04_0-1706692058008.png

 

Also please read the docs link attached before, that has clear explanation on how you can achieve this easily. 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

shloke04
Kilo Patron

Hi @BALAJI K R ,

 

Please follow the steps below to achieve this both in form and list view together. You do not need a script for this requirement:

 

1. Please make use of dependent fields concept in ServiceNow - https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/field-administr...

 

2. Navigate to dictionary of "Product" attribute and click on "Advanced view" and select Supplier as a dependent field. For example please see a similar thing done OOTB for incident table between Category and Subcategory attribute:

 

This will work for both form and list view.

 

shloke04_0-1706687343954.png

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Yes, but is it possible to give 2 dependent values to a single choice in product?

For example:

supplier fields has supplier A and supplier B

Product has A,B & C

When supplier field is selected as supplier A then product should show A & B

When supplier field is selected as supplier B then product should show B & C

@BALAJI K R 

 

Yes, absolutely.

1. Once you have selected the dependent field as "Supplier" in Product dictionary form. 

2. Scroll down to choices and define as many choice you want to make visible based on selection of Supplier as shown below:

shloke04_0-1706692058008.png

 

Also please read the docs link attached before, that has clear explanation on how you can achieve this easily. 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Anubhav24
Mega Sage
Mega Sage

Hi @shloke04 ,

Yes it is possible using g_form.addOptions and remove options but as already mentioned by other colleague you can do it by dependent field concept, hence you should be going for dependent field OOB feature.

 

Please mark helpful/correct if my response helped you.