- 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 07:43 AM
Thank you 🙂