How to put filter on a reference field based on the value of another field in service portal?

Naina3
Kilo Contributor

Hi,

I have a requirement in which I need to put a filter on the value of a reference field in service portal based on another field value. Basically, there are 2 reference fields Division and Department. There is a field "Company" in the Department field's reference table which is same as Division field's name, so, Department should show only those choices or selections whose company field value matches with the division field's name (Division field is always selected first). I used following code but it is not working for me:

HTML:

  <div class="row">
            <div class="col-md-6">
               <label class="required"> Division </label>  <br/>
               <sn-record-picker id="division1" field="c.division" table="'core_company'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" default-query="'u_abc_division=true'"></sn-record-picker>
            </div>

<div class="row">
            <div class="col-md-6">
               <label class="required"> Department </label>  <br/>
               <sn-record-picker id="department" field="c.department" table="'cmn_department'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100"  default-query="company.nameSTARTSWITH{{data.division1}}"></sn-record-picker>
            </div>

 

Client controller:

$scope.$on("field.change", function(evt, parms) {

         if (parms.field.name == 'division1') {

                   c.data.division1_dv = parms.displayValue;

                   c.data.division1 = parms.newValue;

         }

});

Can anyone help me fix this?

Thanks in advance!

2 REPLIES 2

Bogdan18
Tera Guru

Hi Naina,

 

You have to apply the logic in the catalog item itself. I will give you an example below so you can get an idea:

 

Company - reference field on the core_company table

 

Location - reference field on the cmn_location table with an advanced reference qualifier set to javascript:"company=" + current.variables.company

 

find_real_file.png

 

Functionality:

 

If the Company field is selected then only those locations which have that Company listed will show up under the Location field.

 

find_real_file.png

 

regards,

Bogdan

Naina3
Kilo Contributor

Hi Bogdan,

Actually the thing is that putting anything in the reference qualifier is not going to work as we have customized this particular service to be service portal widget. So, for that any scripting or customization done on maintain item won't work on the order form. One will have to write it in the widget itself.

 

Thanks!