How to pass the reference value from the HTML to the client controller in the widget

Samiksha2
Mega Sage

Hi,

I want to pass the reference value from the HTML to the client controller in the widget.

Here is my code:

HTML:

<sn-record-picker field="name" table="'sys_user'" id="reference_field" display-field="'name'" display-fields="'name,user_name'" value-field="'sys_id'" search-fields="'name'" page-size="50" ng-change="c.referChange()" ></sn-record-picker>

 

Client controler:


api.controller=function($location,$scope) {
/* widget controller */
var c = this;

c.referChange=function(){

$location.url('sp?id=portal&table=u_user_table&filter=u_user_delegateLIKE'+(what will be here? how to add the value of reference));

}

};

 

Please help in this.

 

Thanks,

Samiksha

13 REPLIES 13

Thank you @Syedmd08 for your help. 
Now url is changing but value is coming as undefined.

<input type="hidden" id="reference_field" ng-model="c.selectedReference.sys_id">

<sn-record-picker field="name" table="'sys_user'" id="reference_field_picker" display-field="'name'" display-fields="'name,user_name'" value-field="'sys_id'" search-fields="'name'" page-size="50" ng-model="c.selectedReference" ></sn-record-picker>

 

In this code, we are now using the ng-model directive to bind both the c.selectedReference object and the sys_id property of the object to the hidden input field.

In the client controller, we can now access the selected reference value by accessing the sys_id property of the c.selectedReference object. Here's the updated referChange function:

 

api.controller = function($location, $scope) {
var c = this;

c.referChange = function() {
var selectedSysId = $scope.c.selectedReference.sys_id;
$location.url('sp?id=portal&table=u_user_table&filter=u_user_delegateLIKE' + selectedSysId);
};
};

 

With these changes, the referChange function should now receive the correct value of the reference field when it is changed by the user in the sn-record-picker.

Nothing happened @Syedmd08 .😣.
Now url is not changing.🙁

Hi @Syedmd08 ,

 

I got the solution. As you suggested to create a hidden input. I did the same and write a server script to put the value in that input and after that i pass that value through ng-model.

Thanks for the suggestion.