Client/Server script communication
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2017 12:35 AM
ServiceNow angularjs client/server script communication
we are working in ServiceNow and am creating a widget that displays a list of Cases along with Printing Options. We would like to populate an array based on the Cases and Printing Option selected, but are having issues passing things between client and server scripts. Below is my HTML and snapshot of what the widget looks like:
<div class="btn-group" role="group">
<button id="btnGroupDrop1" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Printing Options <i class="fa fa-caret-down"/>
</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1" >
<li ng-repeat="print in c.docSetPrint">
<a class="dropdown-item" href="#">{{print.document_set_name}}</a>
</li>
</div>
</div>
<table id="print_table" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th><input type="checkbox" id="selectAll"/></th>
<th>${Case Number}</th>
<th>${Short Description}</th>
<th>${Start Date}</th>
<th>${Work Location}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in c.ONCase track by $index">
<td><input type="checkbox" id="{{item.number}}"/></td>
<td>{{item.number}}</td>
<td>{{item.short_description}}</td>
<td>{{item.start_date}}</td>
<td>{{item.location}}</td>
</tr>
</tbody>
</table>
In the above table, i would like to loop through each entry and if it has been selected or checked, then return an array of all the Case Numbers selected. In my client script, I have something like this so far:
c.printDocs = function(){
var arr = [];
for(i=0; i<c.data.ONCase.length; i++){
if(document.getElementById(c.data.ONCase[i].number).checked == true){
arr.push({
case_num: c.dataONCase.number <--??
});
}
}
c.server.get({
action: 'print_docs',
cases: arr
})then(function(response) {
// do stuff after
});
};
I'm pretty confused on how the scripting between client and server scripts. Once I do get the array of Case Numbers, how do I then pass that along to the server?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-09-2017 01:31 AM
Hi Leviya,
This might help.
https://serviceportal.io/communicating-between-the-client-script-and-the-server-script-of-a-widget/
Thanks
Gaurav