Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

HoTwo snRecordPicker's depend on another

techies
Kilo Expert

Hi All,

I have two Sn-record-pickers as follows.

        <sn-record-picker field="company"   table="'core_company'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>

                <sn-record-picker field="location" table="'cmn_location'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>

I was wondering if it is at all possible to have the location filtered by the company, i.e default-query="company.nameSTARTSWITH{{data.company}}". I am stuck as to how I could approach this. Any help would be appreciated.

Thanks.

1 ACCEPTED SOLUTION

larstange
Mega Sage

Hi



You also need to add a listener to capture when the record pickers are updated



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


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


                  c.data.company_dv = parms.displayValue;


                  c.data.company = parms.newValue;


        }


});


View solution in original post

8 REPLIES 8

larstange
Mega Sage

Hi



Yes that is easy - you do this way:



In your client script you create a object which you bind record picker to



c.company_picker = {


      displayValue: c.data.company_dv,


      value: c.data.company,


      name: 'company'


};



then you bind the comanpy record picker to this object


<sn-record-picker field="c.company_picker"   table="'core_company'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>



In your location picker you then reference the value selected in company


<sn-record-picker field="location" table="cmn_location'" default-query="'company.nameSTARTSWITH' + c.data.company_dv" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>


Hi thanks for the reply


I tried that method but it appears that the locations record picker does not update dynamically. I'm thinking that the defauly querys syntax might be a bit off. If not ill fiddle around with it again.


Thanks


Thanks, @Lars


But unable to do it. Can you please give me demo or a update set so that it can make me understand.


It will really help me.



Thanks,


Saptashwa


larstange
Mega Sage

Hi



You also need to add a listener to capture when the record pickers are updated



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


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


                  c.data.company_dv = parms.displayValue;


                  c.data.company = parms.newValue;


        }


});