service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 12:18 AM
Hello Team,
I Need create the Service Portal, where currently logged in user incident details needs to be displayed in incident list can you guys help me to with this.
I am able to display all user incident details in my currently widget.
These are following code:-
HTML Code :
<div>
<div class="filter-breadcrumbs">
<sp-widget widget="data.filterBreadcrumbs"></sp-widget>
</div>
<table id="customers">
<tr>
<th ng-repeat="x1 in data.header" ng-click="sort(data.fieldList[$index])">{{x1}}
<span class="sortorder descending" ng-show="(sortKey==data.fieldList[$index] && reverse==false)"></span>
<span class="sortorder" ng-show="(sortKey==data.fieldList[$index] && reverse==true)"></span>
</th>
</tr>
<tr ng-repeat="c in data.rec | orderBy: sortKey:reverse | limitTo:maxInc: currentIndex">
<td ng-repeat="cal in data.fieldList">
{{c[cal]}}
</td>
</tr>
</table>
<div>
<ul class="pagination" style="float:right">
<li ng-repeat="i in getNumber(pageNumber) track by $index" ng-click="pageChange($index)" ng-class="isActive($index)" ><a>{{$index+1}}</a></li>
</ul>
</div>
</div>
Client Side Code:-
api.controller=function($scope,spUtil) {
/* widget controller */
// Start for pagination
$scope.totalInc= $scope.data.rec.length;
$scope.maxInc= 10; $scope.currentIndex=0;
$scope.pageNumber= Math.ceil($scope.totalInc/$scope.maxInc);
$scope.currentPage=0;
$scope.getNumber=function (number){
return new Array(number);
}
$scope.pageChange = function (index){
$scope.currentPage=index;
if(index==0)
$scope.currentIndex=0;
else
$scope.currentIndex= $scope.maxInc*(index);
}
$scope.isActive = function (index){
if($scope.currentPage == index)
return "active";
else
return "";
}
// End for pagination
/* For breadcams */
// var c = this;
// $scope.$on('widget-filter-breadcrumbs.queryModified', function(e, newFilter){
// $scope.data.filter = newFilter;
// spUtil.update($scope).then(function(){
// $scope.totalInc= $scope.data.rec.length;
// $scope.maxInc= 10; $scope.currentIndex=0;
//// $scope.pageNumber= Math.ceil($scope.totalInc/$scope.maxInc);
$scope.currentPage=0;
// });//
// });//
// End Here
//Shorting
// $scope.reverse = false;//
//$scope.sortKey = 'number';
// $scope.sort = function (keyname) {
// $scope.sortKey = keyname;
// $scope.reverse = !$scope.reverse;
// $scope.currentIndex=0;
// } //
//End Shorting
};
Server side Code :-
(function() {
data.table = 'incident';
data.fieldList= 'number,short_description,description,caller_id,priority,category,cmdb_ci';
data.fieldList=data.fieldList.split(',');
var header='Number,Short Description, description, Affected User,Priority,category,Configuration item';
data.header=header.split(',');
data.rec=[];
data.filter = data.filter || input.filter;
data.filter2 = data.filter2|| input.filter2;
var gr1= new GlideRecord('incident');
var gr = new GlideRecord(data.table);
gr.addEncodedQuery('active=true')
if(data.filter)gr.addEncodedQuery(data.filter);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()){
var j={};
for(var i=0; i<data.fieldList.length; i++){
j[data.fieldList[i]]=gr.getDisplayValue(data.fieldList[i]);
}
j.sys_id=gr.getValue('sys_id');
j.checkBox=false;
data.rec.push(j);
}
// var breadcrumbWidgetParams = {
// table: 'incident',//
//query: data.filter,//
// enable_filter: true//
// };//
// data.filterBreadcrumbs = $sp.getWidget('widget-filter-breadcrumbs', breadcrumbWidgetParams);//
})();
Could you please advise me in the server-side code the with currently logged in user. please correct me in in server side code with simple one
Thank you.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 12:44 AM
var gr = new GlideRecord(data.table);
gr.addEncodedQuery('active=true');
gr.addQuery('caller_id',gs.getUserID()); // add this line, it will work for incidents, rest code can remain same.
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 12:58 AM
@RaghavSh I am not able to get the that records , could you please check the server code and explain me where i missed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 03:32 AM
there is an OOB widget called simple list where you can add the query in instance option. Any specific reason for not using that?
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 05:36 AM
@RaghavSh Thanks for the Suggestion. If i want to hyperlink the incident number how i can hyperlink this incident number . Whenever I click on particular incident details , so it will redirect that particular incident number in form so we can update it .
Appreciate if your Help