- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 05:01 AM
Hi,
I want to select multiple records from a list view of table (just like a native view) in service portal and then pass the array of sys ids of the selected records to server side. Please let me know the code for client and server side scripts.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 07:27 AM
Hello,
You will define the selected sys_ids array like this
$scope.data.selection = [].
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);
}
}
};
}
See highlighted code. I modified little bit. I just add data. So that you can use that array in server side script.
In server-side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.incidents = [];
var gr= new GlideRecord('incident');
gr.addActiveQuery();
gr.setLimit(10);
gr.query();
while(gr.next()){
var incident = {}
incident.number = gr.getDisplayValue('number');
incident.short_description = gr.getDisplayValue('short_description');
incident.sys_id = gr.getUniqueValue('sys_id');
data.incidents.push(incident);
}
//gs.addInfoMessage(input);
if(!input){
gs.addInfoMessage("return");
return;
}
else{
var selected_ids = input.selection;
gs.addInfoMessage(input.selected);
}
})();
You can do whatever you want with that array in server-side.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 05:06 AM
Hello,
Show me your widget code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 06:50 AM
Hi
Please find the code below:
HTML Code:
<div>
<!-- your widget template -->
<table>
<tr ng-repeat="incident in data.incidents">
<td>
<input type='checkbox' checklist-model="test" checklist-value='{{incident.sys_id}}' ng-click="selectedList(incident.sys_id)" />
</td>
<td>{{incident.number}}</td>
<td>{{incident.short_description}}</td>
</tr>
</table>
</div>
<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.selection= [];
$scope.selectedList = function (y) {
//alert(y);
if (y) {
var index = $scope.selection.indexOf(y);
if (index === -1) {
$scope.selection.push(y);
}else{
$scope.selection.splice(index, 1);
}
}
};
}
Server Side Code:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.incidents = [];
var gr= new GlideRecord('incident');
gr.addActiveQuery();
gr.setLimit(10);
gr.query();
while(gr.next()){
var incident = {}
incident.number = gr.getDisplayValue('number');
incident.short_description = gr.getDisplayValue('short_description');
incident.sys_id = gr.getUniqueValue('sys_id');
data.incidents.push(incident);
}
//gs.addInfoMessage(input);
if(!input){
gs.addInfoMessage("return");
return;
}
else{
gs.addInfoMessage(input.selected);
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 07:27 AM
Hello,
You will define the selected sys_ids array like this
$scope.data.selection = [].
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);
}
}
};
}
See highlighted code. I modified little bit. I just add data. So that you can use that array in server side script.
In server-side script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.incidents = [];
var gr= new GlideRecord('incident');
gr.addActiveQuery();
gr.setLimit(10);
gr.query();
while(gr.next()){
var incident = {}
incident.number = gr.getDisplayValue('number');
incident.short_description = gr.getDisplayValue('short_description');
incident.sys_id = gr.getUniqueValue('sys_id');
data.incidents.push(incident);
}
//gs.addInfoMessage(input);
if(!input){
gs.addInfoMessage("return");
return;
}
else{
var selected_ids = input.selection;
gs.addInfoMessage(input.selected);
}
})();
You can do whatever you want with that array in server-side.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2018 07:42 AM
Thank you so much Bhagya. It is really helpful. 🙂