Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to update the record individually not everyone ?

Dushyant Siroh
Tera Expert

I need some changes in code i want to update the record individually  but this condition runs only for one record not for all record , i want this type of modification for all the record will update individually means it's doesn't reflect changes in other record please help me

 

HTML:- 

 

<div class="panel panel-default">
<div class="panel-body border" ng-repeat="user in data.array" >
    <div class="form-group">
      <label>Name</label>
      <input class="form-control"  ng-model="user.name">
  </div>
<div class="form-group">
 <label>Email</label>
 <input class="form-control" ng-model="user.email">
 </div>  
<div class="form-group">
<label>Mobile Number</label>
<input class="form-control" ng-model="user.mobile">
</div>  

<div class="form-group">
<input type="submit" value="Update" class="btn btn-primary" ng-click="userUpdate(user)">
 </div>  
   
  <div class="form-group">
<input type="submit" value="Insert" class="btn btn-primary" ng-click="userInsert(users)">
 </div>  
  
    </div>
  
</div>

 

  CLIENT SCRIPT :-

 

api.controller=function($scope) {
  /* widget controller */
  var c = this;
	$scope.userUpdate=function(user){
		$scope.data.name=user.name;
		$scope.data.email=user.email;
		$scope.data.mobile=user.mobile;
		alert(user.email);
		$scope.server.update();
		location.reload();
	}

}

 

 

SERVER SCRIPT:-  

 

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

      /*1. Declare the array*/
	data.array=[];
/*2. Glide record on table*/
var grInc = new GlideRecord('u_artificatory');
grInc.Query('sys_id','122');
grInc.query();

while(grInc.next()){
/*2.1 Create empty object*/
data.array.push({
               /*2.2 Set object values*/
name:grInc.u_name.toString(),
email:grInc.u_class.toString(), 
mobile:grInc.u_section.toString() 	
});
} 

	
		var gr2=new GlideRecord('u_artificatory');
	gr2.addQuery('sys_id','122');
		gr2.query();
		if(gr2.next())
			{
				gr2.u_name=input.name;
				gr2.u_class=input.email;
				gr2.u_section=input.mobile;
				gr2.update();
			}
	

})();

 

Screenshot 2024-02-08 at 3.11.26 PM.jpeg

Please Update this code ???

0 REPLIES 0