why Glide Record query is not running for non admin users and how to fix this issue?

shabbir5
Tera Guru

Hello Everyone,

 

I have a GlideRecord query in a widet to create SC_TASK record when user click on "Reopen" buttton.

 

as an admin when i click "reopen" , my code is working and sc task is creating

 

but when i ipersonate and test with an ITIL user , then the code is not working , i just printed the getRowCount() , i am getting 0 when i tested with ITIL user

 

below is my script

 

if
            var lastClosedTask = new GlideRecord('sc_task');
            lastClosedTask.addQuery('request_item',sys_id);
            gs.info("Sysid of RITM :"+sys_id);
            gs.info("Sysid of RITM1 :"+gr.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; // Assign the specified assignment group
                newTask.short_description = "Ticket is reopened by " + gs.getUserDisplayName();
                newTask.insert();
                gs.info("NEW SCTASK Created : " +newTask.number);
            } else{
                gs.info("Im from line no.78");      
                gs.info("No SCTASK is present for RITM :"+gr.number);  
            }
            /
            }
        }
please let me know how to fix the issue
@Mohammed Ali  @ankur b
2 REPLIES 2

Ankur Bawiskar
Tera Patron

@shabbir5 

it means there is Query BR on sc_task is blocking the query

try this

var lastClosedTask = new GlideRecord('sc_task');
lastClosedTask.addQuery('request_item', sys_id);
gs.info("Sysid of RITM :" + sys_id);
gs.info("Sysid of RITM1 :" + gr.sys_id);
lastClosedTask.addQuery('state', 3);
lastClosedTask.orderByDesc('closed_at'); // Get the most recent closed task
lastClosedTask.setLimit(1);
lastClosedTask.setWorkflow(false);
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; // Assign the specified assignment group
newTask.short_description = "Ticket is reopened by " + gs.getUserDisplayName();
newTask.insert();
gs.info("NEW SCTASK Created : " + newTask.number);
} else {
gs.info("Im from line no.78");
gs.info("No SCTASK is present for RITM :" + gr.number);
}
/
}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

@shabbir5 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.