Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Ankur Bawiskar
Tera Patron

@Alia 

add/remove option won't work.

You can use advanced ref qualifier on Field B and Field C and use sysIds of those records

something like this on Field B

javascript: var query; if(current.fieldA.indexOf('Choice1RecordSysId') > -1) query = 'sys_idINchoice11SysId,choice22SysId'; query;

Something similar on Field C

javascript: var query; if(current.fieldA.indexOf('Choice1RecordSysId') > -1) query = 'sys_idINchoice111SysId,choice222SysId'; query;

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

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

@Ankur Bawiskar 

I am trying using a system property and call it in a script include and the script include method, i am calling in the reference qualifier for the dependent field. 

system property :-

{

'sysIDField1Choice1':'sysIDField2Choice1,sysIDField2Choice2',

'sysIDField1Choice2':'sysIDField2Choice11,sysIDField2Choice22'

}

Please help me with the script to return the individual value for each field choice. For me, its returning only the first value for the choice field.

 

@Alia 

have 2 system properties for each

Each property will hold sysIds as comma separated values

property1 - sysIDField2Choice1,sysIDField2Choice2

property2 - sysIDField2Choice11,sysIDField2Choice22

Then update your reference qualifier as this

something like this on Field B

javascript: var query; if(current.fieldA.indexOf('Choice1RecordSysId') > -1) query = 'sys_idIN' + gs.getProperty('property1'); query;

Something similar on Field C

javascript: var query; if(current.fieldA.indexOf('Choice1RecordSysId') > -1) query = 'sys_idIN' + gs.getProperty('Property2'); query;

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

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

@Ankur Bawiskar 

The system property is like below

system.property1 -

{"Key1":"Value1,value2,value3",

"Key2":Value11,value22,value33"}

when i select key 1, it should display the value1, value 2 and value 3 and when i select key 2, it should display value11, value22, value33

 

I have written a script include and called the method in the reference qualifier

Code-

getMethod1 : function(value){

var prop=gs.getProperty('propertyname');

var obj = JSON.parse(prop.toString());

for (var key in obj){

var val = obj[key];

var valArr =[];

for(var j=0,j<val.length;j++){

if(val[j] in obj){

valArr.push(obj.val[j])

}}}

return "sys_idIN"+valArr.join();

 

I have debugged the code and i am getting the key and the values however when pushing it to the array its not working, please help me with the code where i am making a mistake.

 

Regards

Alia Naz