How to update a record for a table by using widget scripts in servicenow

Annamdevula Di1
Kilo Contributor

Hi All, 

   I have created a widget for updating user table, but its not updating, can you please correct my script where i went wrong, even i have tried for creating incident table record, even its value is not creating, please any one have solution.

find_real_file.png

 

find_real_file.png

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please provide the scripts here for HTML, client and server and don't add screenshots

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Annamdevula Di1
Kilo Contributor

HTML (updating user table)

<div class="panel panel-default">
<div class="panel-body border background" ng-repeat="n in data.UserInfo">
<div class="form-group">
<label>Name</label>
<input class="form-control" ng-model="n.name">
</div>
<div class="form-group">
<label>Phone</label>
<input class="form-control" ng.model="n.phone">
</div>
<div class="form-group">
<label> Mobile Phone</label>
<input class="form-control" ng.model="n.mobile_phone">
</div>
<div class="form-group">
<label>Email</label>
<input class="form-control" ng.model="n.mobile_phone">
</div>
<div class="form-group">
<input type="submit" value="Update" class="btn btn-primary" ng-click="c.updateUser(n)">
</div>
</div>
.
<!-- your widget template -->
</div>

-----------------------------------------------------

Client Script

api.controller=function() {
/* widget controller */
var c = this;
c.updateUser=function(n) {
c.action="update"

c.data.phone=n.phone;
c.data.mobile_phone=n.mobile_phone;
c.data.email=n.email;
c.server.update();
location.reload();
}
}

---------------------------------------

Server Script

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.UserInfo=[];
var gr= new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
if(gr.next())
{
data.UserInfo.push({
name:gr.name.toString(),
phone:gr.phone.getDisplayValue().toString(),
mobile_phone:gr.mobile_phone.toString(),
email:gr.email.toString(),
id:gr.sys_id.toString()

});
}
if(input && input.action=="update")
{
var upd= new GlideRecord('sys_user');
upd.addQuery('sys_id', gs.getUserID());
upd.query();
if(upd.next())
{
upd.phone=input.phone;
upd.mobile_phone=input.mobile_phone;
upd.email=input.email;
upd.update();
}
}
})();

 

HTML(creating a new record for incident table)

<div class="panel panel-default">
<div class="panel-body border background">
<div class="form-group">
<label>Description</label>
<input class="form-control" ng-model="n.description">
</div>
<div class="form-group">
<label>Short Description</label>
<input class="form-control" ng.model="n.short_description">
</div>
<div class="form-group">
<input type="submit" value="Create Incident" class="btn btn-primary" ng-click="c.test(n)">
</div>
</div>

<!-- your widget template -->
</div>

---------------------------------------

Client Scrip

api.controller=function() {
/* widget controller */
var c = this;
c.test = function(n) {

c.data.value1 = n.description;
c.data.value2 = n.short_description;
c.server.update();
//location.reload();
}
};

-------------------------------------

Server Script

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */



var gr = new GlideRecord('incident');
gr.initialize();
gr.setvalue('descritption',input.value1);
gr.setvalue('short_descritption',input.value2);
gr.insert();

})();