show all RITM's pending that logged in users approval needed in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 02:16 PM
Hi ,
I have requirement to show all the RITM's pending that logged in users approval needed in service portal.
Can any one help me with this?
Thanks in Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2023 07:49 PM
HI @Harika1 ,
I trust you are doing great.
To achieve this, you can follow these steps:
- Create a new Service Portal widget or modify an existing one to display the list of pending RITMs.
- Use the GlideRecord API to query the RITM table in ServiceNow.
- Filter the query to retrieve only the RITMs that require the approval of the currently logged-in user.
- Iterate through the result set and display the relevant information in the widget.
- Add the widget to the desired page in the Service Portal.
// Get the current logged-in user
var userId = gs.getUser().getID();
// Create a new GlideRecord instance for the RITM table
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('approval', 'requested'); // Filter for pending approvals
ritmGr.addQuery('approver', userId); // Filter for the current user's approvals
ritmGr.query();
// Iterate through the RITMs and display relevant information
while (ritmGr.next()) {
var ritmNumber = ritmGr.getValue('number');
var ritmShortDescription = ritmGr.getValue('short_description');
// Display the RITM information in the widget or console.log it
console.log('RITM Number: ' + ritmNumber);
console.log('Short Description: ' + ritmShortDescription);
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2023 01:32 PM
Hi Amit,
I tried to code it in this way:
HTML Code
<div class="panel panel-{{options.color}} b">
<div class="panel-heading"> <h2 class="h4 panel-title">
Request Items
</h2>
</div>
<div class="panel-body">
<ul class="list-group" aria-labelledby="header-{{data.sysId}}">
<li class="list-group-item" ng-repeat="RITM_data in ::data.number">
<a style="color:inherit;text-decoration:underline" href="?id=ticket&table=sc_req_item&sys_id={{::RITM_data.sys_id}}">{{::RITM_data.item}}</a>
</li>
</ul>
</div>
</div>
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
// Get the current logged-in user
data.number = [];
var sys_id = $sp.getParameter('sys_id');
data.sysId = sys_id;
var g1 = new GlideRecord('sysapproval_approver');
g1.addEncodedQuery('approver=2850c2bbdb906010fc13e1f5ca96193f^state=requested');
g1.addQuery('source_table','sc_req_item');
g1.query();
while(g1.next()){
var RITM_data = {};
RITM_data.number = g1.sysapproval.getDisplayValue('number');
RITM_data.item = g1.sysapproval.cat_item.getDisplayValue('name');
RITM_data.sys_id = g1.sysapproval.sys_id;
data.number.push(RITM_data);
//data.RITM = g1.sysapproval;
}
})();
Result:
But When I click on it redirects me to 404 - Record not found page
looks like sys_id of the record is not passed properly.
Please help me how to pass this sys_id
Thanks,
Harika