Get current page in service portal

scottl
Kilo Sage

How does one get the sys_id of the current page that the user is viewing in the service portal?

1 ACCEPTED SOLUTION

Hi Scott,



My bad. I thought you were trying to retrieve sys_id from the URL.


You can try below code to get the sys_id of current page,



var page_id = $sp.getParameter('id');


var gr = new GlideRecord('sp_page');


gr.get('id',page_id);


var page_sys_id = gr.sys_id;



Hope this helps.


Do not feel shy to mark correct or helpful answer if it helps or is correct.



Best Regards,


Nitesh Asthana


View solution in original post

13 REPLIES 13

Thank you for posting back


nathanfirth
Tera Guru

If you only need it in the controller, it is already on $scope:



function($scope) {


        var page_id = $scope.page.sys_id;


}


Just to add to this, if you want to get the page id or other parameters when the page changes you can look for the $locationChangeSuccess event and set the current page. The $scope.page.id does not update when the page changes. This is useful when you are looking to highlight menu items or header links. The header and footer are not re-run on page change, and you have to look for a page change event.

In the Client controller:

function($scope, $location) {

var c = this;

c.current_page = $scope.page.id; //set the current page when first loaded

 

$scope.$on.('$locationChangeSuccess', function() {

c.current_page = $location.search().id;

});

}

 

Example HTML:

<ul>

<li ng-class="{'active': c.current_page == 'my_incidents'}">

<a href="?id=my_incidents'">My Incidents</a>

</li>

</ul>

 

Abhijeet Pawar
Tera Contributor

Hello @stephend_angelo ,

I have created side menus on my service portal. when I click on the menu I want to show whatever content is present inside a specific menu beside side menus. I am very new to the service portal how can I achieve this functionality please guide me on this.

Thank you