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

I just tried and it seems to work for me, 

Can you show your script you are running.

-Anurag

This is what I used. Let me know.

 

var gr=new GlideRecord("sys_report");
gr.addEncodedQuery('roles=itil'); // Query for 450 report
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
var grp=new GlideRecord("sys_user_role");
grp.addQuery("sys_id","3be5d3d1b7103300dff9fa13ee11a987"); // 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

}

}

It works for me,

See this is the script i ran

AnuragTripathi_0-1699456138786.png

 

 

And result

AnuragTripathi_1-1699456170230.png

 

-Anurag

I am not sure what happened on my first trial but works now. 

 

Thank you

Cool, happy to help

-Anurag