Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

RITM Reopen button not working properly

Abdul333
Tera Contributor

Hello All,

 

I Created a custom widget and Mapped in Standard Ticket Configurations of sc_req_item Action Widget.

Abdul333_0-1717416083789.png

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.
Abdul333_1-1717416293952.png

 

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.

@Dr Atul G- LNG @Ankur Bawiskar @Community Alums @Mark Roethof 

 

Thanks,

Abdul

 
1 REPLY 1

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Abdul333 

 

I am not expert in code but if you ask me , it is not valid requirement, A Request never have Reopen option, it is pure violation of process. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************