Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Access value from sn-record-picker to update current record

TCole94
Tera Expert

I've created a simple custom widget with a sn-record-picker referencing the sys_user table and also a button to add the new user to the current record. Widget is pictured below:

find_real_file.png

I'm relatively new to custom widgets so the objective would be to pass the selected value from the record-picker to the server script to update the field "u_guest" on the current record (example: Firewall Request: TES001036). 

Once the user clicks "Add User", the u_guest field should be updated on the current record (with the record-picker value) and the page should refresh with an info message. 

Here is what I have so far regarding this widget:

find_real_file.png

The solution should be relatively simple but having difficulty understanding how to pass sn-record-picker values via the client to the server object.

Any help/solutions would be appreciated!!

 

3 REPLIES 3

asifnoor
Kilo Patron

Hi

In your client script controller add code like this.

var c = this;
$scope.$on("field.change", function(evt, parms) {
  if (parms.field.name == 'user') {
     c.data.user = parms.newValue;
  }		
});

Then in your server script you can access it like this

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	var locSysId = "";
if (input.user) {
  guest = input.user;
  var gr = new GlideRecord("your_table");
  if(gr.get(your_record_sys_id)) {
      gr.your_guest_field=guest;
      gr.update();
  }
}
})();

Mark the comment as a correct answer and also helpful if this has solved the problem.

TCole94
Tera Expert

No luck with the following code. What changes would I need to make on my html script to send to the client script? Current html markup is:


<div>
<div class="panel panel-default" ng-if="data.guest.length < 1">
<div class="panel panel-body">
<form class="form-group">
<label for="test">
<h5>${Add Guest}</h5>
</label>
<sn-record-picker
field="user"
table="'sys_user'"
display-field="'name'"
value-field="'sys_id'"
search-fields="'name'"
page-size="100">
</sn-record-picker>
<input class="form-control" ng-model="c.user" type="hidden">
</form>
<button class="btn btn-primary pull-right" ng-click="c.addUser()">
Add User
</button>
</div>
</div>
</div>

 

I will only need the functionality to work once the user clicks the button s well. 

 

Not sure if a custom object needs to be defined.

Hello @TCole94 

 

Did you achieve this? I have the same requirement, Can you please let me know the solution?