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.

Form input data to server

vinithec22
Tera Contributor

html 

<div>
<h1>Check Your Attendance Details</h1>
<input type="text" name="name" placeholder="Enter Your Name" ng-mode="c.data.name">
<input type="text" name="roll_no" placeholder="Enter Roll No" ng-model="c.data.roll_no">
<button ng-click="vis()">Submit</button>
<p>{{data.name}}</p>
<div>

client script

api.controller=function($scope) {
  /* widget controller */
  var c = this;
$scope.vis = function(){
c.server.update();
alert(c.data.name);
}
};
server script
(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
data.name = "";
data.roll_no = "";
if(input){
data.name = input.name;
}
})(); 
i am unable get the data from the input to the server also provide some documentation links to study these things it will be helpful for me
1 ACCEPTED SOLUTION

Utpal Dutta
Tera Guru
Tera Guru

Hi there,

 

Try below:

 

HTML:

<div>
<h1>Check Your Attendance Details</h1>
<input type="text" name="name" placeholder="Enter Your Name" ng-model="c.data.name">
<input type="text" name="roll_no" placeholder="Enter Roll No" ng-model="c.data.roll_no">
<button ng-click="c.vis()">Submit</button>
<p>{{data.name}}</p>
<div>

 

Client Script:

api.controller=function($scope) {
  /* widget controller */
  var c = this;
	c.vis = function(){
c.server.update();
alert(c.data.name);
}
};

 

Server Script:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	data.name = "";
data.roll_no = "";
if(input){
data.name = input.name;
	gs.addInfoMessage(data.name);
}

})();

 

In HTML your ng-model has a typo & you should not write ng-onClick like that. It should be c.functionName()

 

To learn more about Widget scripting please refer here.

 

If my answer helps then please mark it Helpful and Accept this solution.

 

Thanks

View solution in original post

5 REPLIES 5

You can also refer to this ServiceNow DOC for learning.