RITM Reopen button not working as expected
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2024 07:27 PM
Hello All,
I Created a custom widget and Mapped in Standard Ticket Configurations of sc_req_item Action Widget.
Widget Details:
var table = $sp.getParameter("table");
var sys_id = $sp.getParameter("sys_id");
// Valid GlideRecord
var gr = new GlideRecord(table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(sys_id))
return;
var ritm_state = gr.getValue('state');//getting sc_req_item State
var ritm_stage = gr.getValue('stage');
var closedAt = gr.getValue('closed_at')
Server Side Script:
if (input && input.action) {
var action = input.action;
// If RITM table
if (ritm_state == 3 && action == 'reopen') {
// Reopen RITM
gr.setValue('state', 1);
gr.setValue('stage', 'fulfillment');
gr.comments = "Requested Item Reopened by " + gs.getUserDisplayName();
gr.update();
// Copy assignment group from the last closed SC task
var lastClosedTask = new GlideRecord('sc_task');
lastClosedTask.addQuery('request_item',sys_id);
gs.info("Sysid of RITM :"+sys_id);
lastClosedTask.addQuery('state', 3);
lastClosedTask.orderByDesc('closed_at'); // Get the most recent closed task
lastClosedTask.setLimit(1);
lastClosedTask.query();
gs.info('No.of SC TASKS avaialble for RITM '+gr.number+ '--->'+ lastClosedTask.getRowCount());
if (lastClosedTask.next()) {
gs.info("last closed SCTASK No : " + lastClosedTask.number);
var newTask = new GlideRecord('sc_task');
newTask.initialize();
newTask.request_item = sys_id;
newTask.assignment_group = lastClosedTask.assignment_group; // sctask assignment group
newTask.short_description = "Ticket is reopened by " + gs.getUserDisplayName();
newTask.insert();
gs.info("NEW SCTASK Created : " +newTask.number);
} else{
gs.info("No SCTASK is present for RITM :"+gr.number);
}
}
}
The script is not creating new SCTASK if an Enduser click on Reopen button, but as an admin if i click on Reopen button, it is creating new SCTASK for the Same RITM.
Enduser can't have any roles, is this any role issue? Else block log is printing if i impersonated an enduser and click on Reopen button.
This log is printing :No SCTASK is present for RITM : RITM0...
When i tried to Reopen, it prints if block log : NEW SCTASK Created : " +SCTASK....
Can someone please help me on this and correct me if anything i did wrong in the code.
@Ankur Bawiskar @Sandeep Dutta @Mark Roethof @SANDEEP28
Thanks,
Sattar
0 REPLIES 0