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 pass check box value in widget

kambleneeta20
Giga Expert

Hi Experts,

My requirement is I want to pass check box and Comments value to Server Side on clicking of button "Add" which is dynamic in widget -

I am trying below code, however I am getting undefined value and check box selection is getting blank .

I am beginner in widget designing . Can someone please help?

Thanks in advance, 

find_real_file.png

I have written below code HTML Code -

<div class="panel panel-default">
<div class="panel-heading clearfix">
<h3 class="panel-title pull-left">
${Asset Certifications}
</h3>
</div>

<div>
<table class="table">
<thead>
<tr>


</tr>
<table>
<tr ng-repeat="alm in data.alms">
<td>
{{alm.number }}
<input type='checkbox' checklist-model="test" checklist-value='' ng-click="selectedList(alm.sys_id)" />

<label class="checkbox-inline"><input type="checkbox" value="">True</label>
<label class="checkbox-inline"><input type="checkbox" value="">False</label>
<label class="checkbox-inline"><input type="checkbox" value="">Comments</label>
</td>
<td></td>
<td></td>
</tr>
</table>

<div>
<input class="btn btn-primary btn-block" ng-click="c.addtoDashboard()" type="submit" value="Add">
</div>

Client Script -

function($scope) {
/* widget controller */
var c = this;
var sect = []
c.addtoDashboard = function() {

c.data.selected = $scope.selection;
c.server.update().then(function(){
c.data.selected = "";
})
}
$scope.data.selection= [];
$scope.selectedList = function (y) {
alert(y);
if (y) {
var index = $scope.data.selection.indexOf(y);
if (index === -1) {
$scope.data.selection.push(y);
}else{
$scope.data.selection.splice(index, 1);
}
}
};
}

 

Server Script - 

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

var gr= new GlideRecord('alm_hardware');
gr.addQuery("assigned_to", gs.getUserID());

gr.query();


while(gr.next()){
var alm = {}
alm.number = gr.getDisplayValue('serial_number');
alm.short_description = gr.getDisplayValue('display_name');
alm.sys_id = gr.getUniqueValue('sys_id');
data.alms.push(alm);
}
//gs.addInfoMessage(input);
if(!input){


gs.addInfoMessage("return");
return;
}
else{

var selected_ids = input.selection;
gs.addInfoMessage(input.selected);

}
})();

8 REPLIES 8

Upender Kumar
Mega Sage

Try below

 

<input type="checkbox" name="chkRow" ng-model="c.half_day"/>
//Server side
if(input){
   gs.addInfoMessage(input.half_day);
}

Thanks for your reply.

I am getting undefined error.

<div>
<!-- your widget template -->
  <input type="checkbox" name="chkRow" ng-model="c.half_day"/>
  <input type="submit" value="Insert" ng-click="c.update()">
</div>

 

api.controller=function() {
	/* widget controller */
	var c = this;
	c.half_day=false;
	c.update = function() {
		c.data.action = "Test";
		alert(c.half_day)
		c.data.half_day=c.half_day;
		c.server.update().then(function (response) {
			c.data = {};
		})
	}
};

//Server Side
(function() {
	/* populate the 'data' object */
	/* e.g., data.table = $sp.getValue('table'); */
	if(input.action == "Test"){

		gs.addInfoMessage(input.half_day);
	}
})();

Thank you it is working from above way which you have suggested.

However is there any way to pass the sys_id of the record from client to Server , so accordingly record can be update.

Thanks for your assistance.