Fix script to add role to sys_ report table

nebiata
Tera Expert

Currently, about 450 reports are shared with users with itil role. I have a requirement to add an additional role so those reports will be shared with the user who has itil and this additional role. 

 

Thank you

1 ACCEPTED SOLUTION

It works for me,

See this is the script i ran

AnuragTripathi_0-1699456138786.png

 

 

And result

AnuragTripathi_1-1699456170230.png

 

-Anurag

View solution in original post

10 REPLIES 10

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @nebiata 

 

Please use below code

var gr=new GlideRecord("sys_report");
gr.addEncodedQuery('table=sn_audit_engagement'); // Query for 450 report
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
var grp=new GlideRecord("sys_user_role");
grp.addQuery("sys_id","c1b46f9dc31302004e44dccdf3d3ae67"); // sys_id of another role
grp.query();
if(grp.next()){
var num=grp.name;
gs.info(num);
gr.roles=num;

gr.serWorkflow(false);
gr.update(); // added new role in report

}

}

 

Please try and mark Helpful and Correct if it really help you.

Before try to all 450 record, first try 1-2 record for checking it will update correct roles.

Kalyani,

That is a helpful script. However, when I try to run the fix script, it will replace the role. I need the report to be shared with both the ITIL role and this other role. how can I achieve this?

 

Thank you

Try this

 

var gr=new GlideRecord("sys_report");
gr.addEncodedQuery('table=sn_audit_engagement'); // Query for 450 report
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
var grp=new GlideRecord("sys_user_role");
grp.addQuery("sys_id","c1b46f9dc31302004e44dccdf3d3ae67"); // sys_id of another role
grp.query();
if(grp.next()){
var num=grp.name;
gs.info(num);
gr.roles=gr.roles.toString()+','+num;

gr.serWorkflow(false);
gr.update(); // added new role in report

}

}

 

-Anurag

I tried the script you suggested and it removed itil and the function as role. Business_stakeholder is the role I want to add.

nebiata_0-1699454007555.png

Thank you