- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 07:59 AM
when a line manager not approved with in 3 days then the notification goes to linemanager.manager . If linemanager.manager also not approved with in five days( this period line manager should be also able to approve ) , then the request will be cancelled.
Please help anyone to script provide (no flow designer or workflows suggestion).
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 02:31 AM
If you will provide more details than I may help with the proper script.
But you can check once with this
var grRITM = new GlideRecod('sc_req_item');
grRITM.addencodedquery('request.request_state=requested^ORDERBYDESCnumber');
grRITM.query();
while(grRITM.next(()) {
var lineManger = grRITM .u_line_manager; //based upon your field name change this field
var lineManagerMang = grRITM .u_line_manager.manager; //based upon your field name change this field
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addencodedquery('sysapproval='+grRITM .sys_id+'^approver='+lineManger +'^ORapprover='+lineManagerMang +'^ORDERBYsys_created_on');
grApproval.query();
while(grApproval.next()) {
var date1 = new GlideDateTime(); //current date
var createdDate = new GlideDateTime(grApproval.sys_created_on); //approval created date
var dateDiff = GlideDateTime.subtract(createdDate, date1);
var days = dateDiff.getDayPart();
if(days > 4 && grApproval.approver == lineManger ) { //you can change the date value based upon your requirement
///you can call a event to trigger the notification and a script action to create a approval request for line manager's manager if this approval request you are note creating from the flow or somewhere
}
if (days > 5 && grApproval.approver == lineManagerMang) {
write script to cancel the request
}
}
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 10:20 AM
Hi @Nareshpatel
- Are you creating the approval record based on the request or the requested item, or the associated sc_task?
- Do you intend to automatically cancel the approval if it remains unapproved for a total of 5 days? Please confirm.
- This functionality can be implemented using either a Scheduled Job or Flow Designer(you can use the same flow designer which one you are using for the ritm).
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 06:48 AM
could you provided scheduled script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 02:31 AM
If you will provide more details than I may help with the proper script.
But you can check once with this
var grRITM = new GlideRecod('sc_req_item');
grRITM.addencodedquery('request.request_state=requested^ORDERBYDESCnumber');
grRITM.query();
while(grRITM.next(()) {
var lineManger = grRITM .u_line_manager; //based upon your field name change this field
var lineManagerMang = grRITM .u_line_manager.manager; //based upon your field name change this field
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addencodedquery('sysapproval='+grRITM .sys_id+'^approver='+lineManger +'^ORapprover='+lineManagerMang +'^ORDERBYsys_created_on');
grApproval.query();
while(grApproval.next()) {
var date1 = new GlideDateTime(); //current date
var createdDate = new GlideDateTime(grApproval.sys_created_on); //approval created date
var dateDiff = GlideDateTime.subtract(createdDate, date1);
var days = dateDiff.getDayPart();
if(days > 4 && grApproval.approver == lineManger ) { //you can change the date value based upon your requirement
///you can call a event to trigger the notification and a script action to create a approval request for line manager's manager if this approval request you are note creating from the flow or somewhere
}
if (days > 5 && grApproval.approver == lineManagerMang) {
write script to cancel the request
}
}
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 03:11 AM
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('active=true^cat_item=sys_id(mentioned)^approval=requested^sys_created_onRELATIVELT@dayofweek@ago@1');
ritmGR.query();
while (ritmGR.next()) {
var user = ritmGR.u_requested_for.name.toString();
var number = ritmGR.number; // Get the line manager (from variables)
var lineManager = ritmGR.variables.user_id.manager; // Get line manager's manager
var managerGR = new GlideRecord('sys_user');
if (managerGR.get(lineManager)) {
var managerManager = managerGR.manager; // Optional: check if not VIP before triggering
if (!managerGR.manager.vip) {
// Fire the event for each RITM
gs.eventQueue('kf_inactive_line_manager', ritmGR, user, managerManager);
}
}
// var ritm_sys = ritmGR.sys_id;
var approval = new GlideRecord('sc_req_item');
approval.addEncodedQuery('active=true^cat_item=sys_id(mentioned)^approval=requested^sys_created_onRELATIVELT@dayofweek@ago@2');
approval.query();
if (approval.next()) {
approval.state = 'Cancelled';
approval.comments = "REQ auto Cancelled as it is awaiting approval for more than 5 days";
approval.update();
// gs.eventQueue('kf_inactive_line_manager_cancel _request', ritmGR, user, approval);
}
gs.eventQueue('kf_inactive_line_manager_cancel _request', ritmGR, user, approval);
} approval is going to line manager and line manager.manager but ritm i not cancelled could you provide correct script pls