Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to show choice values dynamically based on another field

Priyanka77
Tera Guru

Hi,
I have a requirement to show choice values dynamically based on other field.
Scenario:
1. In record producer i have two fields in which field A' type is "lookup select box" and its populating few values based on reference qualifier of field A and currently has three values in it. 
2. And second field B' type is select box and have 4 choices in it.
Requirement is to show only two values in field B based on when 1 value selected in field A and if other value selected in field A then in field B it should show other two choices.

Please help me with this requirement!

Thanks in advance!
Priyanka

4 REPLIES 4

palanikumar
Giga Sage
Giga Sage

Hi,

You have to use client script for this requirement

use g_form.addOption for adding an option to the choice field

use g_form.removeOption for removing an option

Refer this article for reference

https://servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-options... 

Thank you,
Palani

Thanks for the response.
I used onchange client script but its not working as expected.
Lookupselect box: field A
Selectbox: field B
var a=g_form.getValue('lookupselect box field');
if(a=='value of lookupselect box field'){
g_form.removeOption('selectbox field',',choice value of selectbox');
}

add a alert inside if block and make sure it is getting printed

Thank you,
Palani

Thanks you. Alert is working but its taking only sys id even i tried getDisplayValue then also its not working. Could you please help me to understand how to get display value from "lookup select bos"field.