- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 12:23 AM
hi all,
I'm building a widget to act as a very simple custom record producer. My form only has 2 fields on it, one of which is a reference field to the [sys_user] table. The form creates a new record on the [incident] table with a custom "u_affected_user" field which I want to populate with the reference field from my custom form. But I cannot figure out how to get the value of the reference field to the server script to use in the GlideRecord that is creating the new record. When I click "Submit" button it creates the record, and the "short_description" field populates fine, but the anyone see what I'm missing?
Here are the scripts:
HTML
<div class="panel panel-default">
<div class="panel-heading">
<div class="form-group">
<!-- Affected user : Reference field: THIS ONE IS NOT PASSING THE VALUE THE SERVER SCRIPT-->
<div class="form-group">
<label>Search for your name:</label>
<sn-record-picker field="c.affected_user" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>
</div>
<div class="form-group">
<label>Description</label>
<input class="form-control" ng-model="c.data.short_description">
</div>
<!--The Submit button-->
<div class="form-group">
<input class="btn btn-primary btn-block" ng-click="c.addItem()" type="submit" value="Submit">
</div>
</div>
</div>
CLIENT SCRIPT
function($scope, spUtil) {
var c = this;
c.addItem = function(){
c.server.update().then(function(response){
spUtil.update($scope);
c.data = {};
$scope.c.affected_user.value = '';
}) }
}
SERVER SCRIPT
(function() {
if(!input)
return;
input.requested_by = gs.userID();//THIS IS TO SET THE [caller_id] FIELD TO THE LOGGED IN USER
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = input.short_description;
gr.caller_id = input.requested_by;
gr.u_affected_user = input.affected_user;//THIS IS WHAT IS NOT WORKING
gr.insert()
})();
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 12:40 AM
HI,
My HTML:
<sn-record-picker field="data.user"
table="'sys_user'"
display-field="'name'"
value-field="'sys_id'" search-fields="'user_name,name'"
page-size="100">
</sn-record-picker>
Client COntroller:
function($scope,spUtil,$rootScope) {
/* widget controller */
var c = this;
c.data.user = {value:'',displayValue:''};
}
Server:
We can access as below:
input.user.value
Thanks,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2019 12:51 PM
Hi Ashutosh...one more question...is it possible to make this field mandatory?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2019 01:28 AM
Hi,
Yes we can make this mandatory.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 11:14 AM
How is this achieved?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 12:30 AM
Here you go:
<span style="padding-right: .25em" title="Mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.user.value != ''}"></span>
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 09:40 AM
so to make the <sn-record picker" field mandatory, would it go like this?
<span style="padding-right: .25em" title="Mandatory" class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': data.user.value != ''}">
<sn-record-picker field="data.user"
table="'sys_user'"
display-field="'name'"
value-field="'sys_id'" search-fields="'user_name,name'"
page-size="100">
</sn-record-picker></span>
with this it's making the field shrink...is there a way to keep this field at full width?