How to pass check box value in widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2021 03:43 AM
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,
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);
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2021 04:51 AM
Try below
<input type="checkbox" name="chkRow" ng-model="c.half_day"/>
//Server side
if(input){
gs.addInfoMessage(input.half_day);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2021 10:03 AM
Thanks for your reply.
I am getting undefined error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2021 10:23 AM
<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);
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2021 11:06 AM
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.