Access value from sn-record-picker to update current record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 10:21 AM
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:
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:
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!!
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 11:03 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2020 01:19 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2022 07:38 AM
Hello
Did you achieve this? I have the same requirement, Can you please let me know the solution?