The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to Filter Device Records Based on Test Type and Test to Perform in a List Collector Field?

Community Alums
Not applicable

I have a form with three fields on the "Test Execution" form in ServiceNow:

  1. Test Type field with the following options:

    • "Scenario A" (value 1)
    • "Scenario B" (value 2)
  2. Test to Perform field, which is dependent on the Test Type field, with these choices:

    • For Scenario A (value 1):
      • "Test A" (value 31)
      • "Test B" (value 29)
      • "Test C" (value 26)
      • "Test D" (value 25)
    • For Scenario B (value 2): No available options.
  3. Device list collector field, which references the Device table. The table has the following columns:

    • device
    • device_name
    • asset_id

Each Test Type and Test to Perform combination is mapped to specific devices via asset_id. I've hardcoded the mappings like this:

 

{
"1": {
"25": [1001, 1002],
"26": [1001, 1002],
"29": [1003],
"31": [1004, 1005, 1006]
},
"2": [2001, 2002, 2003, 2004]
}

The requirement is that when a user clicks on the magnifying glass to select a device, only the devices with the corresponding asset_id from the mapping should be displayed. The user should then be able to add these filtered records to the list.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If you truly have a List Collector, not a List, then you must be referring to variables on a Catalog Item, not fields on a table.  This distinction is important in this case as the solution depends on it.  So when Scenario A is populated for the first variable, and Test D is populated for the second variable, does the 'hardcoded' mapping already exist anywhere?  If it's the value of a system property, or only exists in how you want the available devices to be filtered, the List Collector reference qualifier needs to call a Script Include, passing in the value of the the first two variables, something like this:

BradBowman_0-1725905685140.png

where test_type and test_to_perform are the variable names for the first two.  The Variable attributes ensures that the list filter is updated when either of the two other variables is updated.

 

The Script Include (named CatalogUtil in this example) will contain a function(named getDevices in this example) which will execute a GlideRecord on the Device table with addQuery lines within if statements so that it returns only the records that match the mapping.  For each record returned, push the sys_id to an array, then the joined array is returned like this:

return 'sys_idIN' + devArr.join(',');

where devArr is the name of the array you pushed each sys_id to.

You may need to add the asset_id field to the display or list view, depending again if this is a List type field or a List Collector, and if so if you are using this in Service Portal /ESC, and/or using the glide_list attribute to make it display like a list field instead of the Available and Selected boxes. 

 

 

View solution in original post

4 REPLIES 4

debendudas
Mega Sage

Hi @Community Alums ,

In this scenario, you can use Advanced Reference Qualifier.

Please refer to this article for more information: Reference Qualifiers in ServiceNow - ServiceNow Community

 

Quick tip:

1. Use a script include and define a function. This function must accept the 'Test Type' and 'Test to Perform' as input parameters from the form

2. Do all the complex calculations in that function

3. Return the list of sys_ids of the Device table which will match with the condition

4. Use this same function in the Advanced reference qualifier

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍

Brad Bowman
Kilo Patron
Kilo Patron

If you truly have a List Collector, not a List, then you must be referring to variables on a Catalog Item, not fields on a table.  This distinction is important in this case as the solution depends on it.  So when Scenario A is populated for the first variable, and Test D is populated for the second variable, does the 'hardcoded' mapping already exist anywhere?  If it's the value of a system property, or only exists in how you want the available devices to be filtered, the List Collector reference qualifier needs to call a Script Include, passing in the value of the the first two variables, something like this:

BradBowman_0-1725905685140.png

where test_type and test_to_perform are the variable names for the first two.  The Variable attributes ensures that the list filter is updated when either of the two other variables is updated.

 

The Script Include (named CatalogUtil in this example) will contain a function(named getDevices in this example) which will execute a GlideRecord on the Device table with addQuery lines within if statements so that it returns only the records that match the mapping.  For each record returned, push the sys_id to an array, then the joined array is returned like this:

return 'sys_idIN' + devArr.join(',');

where devArr is the name of the array you pushed each sys_id to.

You may need to add the asset_id field to the display or list view, depending again if this is a List type field or a List Collector, and if so if you are using this in Service Portal /ESC, and/or using the glide_list attribute to make it display like a list field instead of the Available and Selected boxes. 

 

 

Community Alums
Not applicable

Sorry for typo, I have a List type field on form.

The reference qualifier will be similar, passing current.field_name to the Script Include, instead of current.variables.variable_name.  The attribute is the same, or may not be needed on a List field.