How to show/hide choices for list collector variables

Koki Sugimori
Tera Contributor

We are currently creating two variables (a select box variable and a list collector variable) in the catalog item.

 

As an example, we have created choices A, B, C, D, and E for the select box variable and choices 1, 2, 3, 4, and 5 for the list collector.

 

【Set values for the list collector】
 List table: Question Choice[question_choice].
 Reference qualifier: sys_created_onON2024-12-25@javascript:gs.dateGenerate('2024-12-25','start')@javascript:gs.dateGenerate('2024-12 -25','end')

 

【Question】
I would like the list collector variable to show 1, 2, and 3 (4 and 5 are hidden) when A, B, and C are selected in the select box variable, while 4 and 5 are shown (1, 2, and 3 are hidden) when D and E are selected.

 

This is indicated in the image diagram.

KokiSugimori_0-1736316638084.png

 

Can anyone assist me on how to implement the above?
Thank you in advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Koki Sugimori 

you can apply advanced ref qualifier on list collector and make it dependent on select box

Something like this

Ensure you give the correct variable name and correct sysIds for the question choices from question_choice table

javascript: var val = current.variables.selectBoxVariableName; var query; if(val == 'A' || val == 'B' || val == 'C') query = 'sysIDINChoice1SysId,Choice2SysId,Choice3SysId'; else query = 'sys_idINChoice4SysId,Choice5SysId'; query;

In variable attributes please give this

ref_qual_elements=selectBoxVariableName

 

AnkurBawiskar_0-1736402248663.png

 

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

View solution in original post

9 REPLIES 9

@PraveenK1149237 

 

I am sorry that I do not quite understand the intent of your question.
What do you mean by “some kind of relationship”?

 

【To add to my reply yesterday】
If I select A in the select box, when I open the pull-down in the list collector, it shows 4 and 5, which are not related to each other.
I mean I want to hide this.

 

KokiSugimori_1-1736396407577.pngKokiSugimori_2-1736396410503.png

 

If you know of any solution to this, please support me.
Thank you in advance.

Ankur Bawiskar
Tera Patron
Tera Patron

@Koki Sugimori 

you can apply advanced ref qualifier on list collector and make it dependent on select box

Something like this

Ensure you give the correct variable name and correct sysIds for the question choices from question_choice table

javascript: var val = current.variables.selectBoxVariableName; var query; if(val == 'A' || val == 'B' || val == 'C') query = 'sysIDINChoice1SysId,Choice2SysId,Choice3SysId'; else query = 'sys_idINChoice4SysId,Choice5SysId'; query;

In variable attributes please give this

ref_qual_elements=selectBoxVariableName

 

AnkurBawiskar_0-1736402248663.png

 

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

@Ankur Bawiskar 

Thank you very much.
For me, this solution is very helpful.

 

I would like to confirm one point.

I changed the ref qualifier you gave me to the correct variable name and sysIds, but all records in the [question_choice] table show up in the list collector.

Shouldn't it be javascript: not javascript:?

 

ref qualifier:Before modification】

 

javascript: var val = current.variables.selectBoxVariableName; var query; if(val == 'A' || val == 'B' || val == 'C') query = 'sysIDINChoice1SysId,Choice2SysId,Choice3SysId'; else query = 'sys_idINChoice4SysId,Choice5SysId'; query;

 

 

【ref qualifier:After modification】

javascript: var val = current.variables.selectBoxVariableName; var query; if(val == 'A' || val == 'B' || val == 'C') query = 'sysIDINChoice1SysId,Choice2SysId,Choice3SysId'; else query = 'sys_idINChoice4SysId,Choice5SysId'; query;

 

I would appreciate confirmation on this.

@Koki Sugimori 

I also informed to give the variable attributes for the list collector. Did you give that?

ref_qual_elements=selectBoxVariableName

 

AnkurBawiskar_0-1736476834689.png

 

 

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

@Ankur Bawiskar 

Thank you very much.


Thanks to you, I have a solution!

I approve this as a solution.