Problem loading to List Collector

servicetrout
Tera Expert

Trying to set up a List Collector field in a Record Producer based on a custom table with the following fields

Step 1) User selects Department in record producer field

Step 2) Client script should load only the divisions associated to the department selected into the List Collector

Table: u_dept2div

Fields: [ u_deptId, u_deptname, u_divId, u_divname]

e.g.

  100   Anesthesiology       1 Anesthesiology

  200   Medicine         2 Allergy

  200   Medicine         3 Cardiology

  200   Medicine         4 Emergency

  200   Medicine         5 Pulmonary

...

Below is my code.   Currently, all divisions in the table are loaded into the list selector, which does not change.

I have confirmed the department selection is working fine, as it updates an approver field in the Record producer just fine.

function onChange() {

    if ( newValue == '') {

          return;

    }

  //   User selected department on form

  var choice = g_form.getValue('u_deptchoice');

//   alert(choice);

//remove all items from list to start

// Used the g_form.clearOptions() function instead of g_form.removeOption() function

g_form.clearOptions('u_test_divs');

//build a new list based on the   Department selected

var gp = new GlideRecord('u_dept2div');

// gp.addNotNullQuery('u_deptname',choice);       // Not working try hardcoding one Department

gp.addNotNullQuery('u_deptname','Medicine');

gp.orderBy('u_divname');

gp.query();

while(gp.next()){

  g_form.addOption('u_test_divs', gp.value, gp.label);

}

}

The challenge is the user needs to be able to select more than one division.

1 ACCEPTED SOLUTION

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

List collectors work differently than choice lists (drop downs).   This link should give you some pointers.   Rather than requerying using a GlideRecord call, you need to reset the filter (kind of like a reference qualifier).   It's a bit convoluted, but I'm not aware of a simpler way.



Changing the Filter of a List Collector Variable via Client Script - ServiceNow Guru


View solution in original post

1 REPLY 1

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

List collectors work differently than choice lists (drop downs).   This link should give you some pointers.   Rather than requerying using a GlideRecord call, you need to reset the filter (kind of like a reference qualifier).   It's a bit convoluted, but I'm not aware of a simpler way.



Changing the Filter of a List Collector Variable via Client Script - ServiceNow Guru