Need help with script to pass value from <sn-record-picker> field on custom widget HTML to the server script to be used in a GlideRecord

patricklatella
Mega Sage

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()

})();

 

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

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

View solution in original post

14 REPLIES 14

patricklatella
Mega Sage

Hi Ashutosh...one more question...is it possible to make this field mandatory?

Hi,


Yes we can make this mandatory.


Thanks,
Ashutosh

How is this achieved? 

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

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?

find_real_file.png