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.

Map a field having choices based on the other field choice

Alia
Tera Contributor

Hi Team,

 

Requirement-

There are 3 fields of data type as List (multi-select) for a table. We are referencing them to another table.

Field A-- choice 1, choice 2, choice 3, Choice 4

Field B-- choice 11, Choice 22, choice 33, Choice 44

Field C--choice 111, Choice 222, choice 333, choice 444

 

On select of field A and choice 1, it should show field B with choice 11, choice 22 and Field C with choice 111, choice 222 and like wise.

 

Tried with On change client script using add/removeOption however seems they dont work with List type of field.

 

Please suggest on this .

 

Regards

Alia Naz

6 REPLIES 6

@Alia 

it should work if you are getting correct sysIds and correct ref qualifier is applied

your script include function is not doing anything with the value passed i.e. fieldA value

the syntax should be this

javascript: new ScriptInclude().getMethod1(current.fieldA);

update script include function as this

getMethod1: function(value) {
    var prop = gs.getProperty('propertyname');
    var obj = JSON.parse(prop.toString());

    var valArr = [];
    for (var key in obj) {
        if (key == value) {
            var val = obj[key].split(',');
            for (var j = 0; j < val.length; j++) {
                valArr.push(val[j]);
            }
        }
    }

    return "sys_idIN" + valArr.join(',');
}

I hope I have provided enough guidance on your question and you can enhance it further based on your developer skills and experience.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Raj_Nishant92
Tera Contributor

Hi @Alia 

1. Create a UI Policy to control the visibility of Field B and Field C based on the selection in Field A. This will hide/show the fields as necessary.

2. You'll need a Client Script that listens for changes to Field A and dynamically updates the available choices for Field B and Field C.

 

Unfortunately, you cannot directly use the addOption() or removeOption() methods on a multi-select field.

 

Pls hit like if it is helpful

 

Thanks