Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Forum Read Permissions from a script

RaysOdyssey
Tera Contributor

Hello,

 

I am wondering if anyone has figured out a way to calculate forum readability from a server-side script in ServiceNow.

Essentially, I am hoping to gather all Community Forums that a user has read access to.

 

So far, I found sn_communities.CommunityUserImpl has some functions to calculate user readability, but it just returns a blank array.

 

var user = "sys_id of the user";
var scrInc = new sn_communities.CommunityUserImpl(user);
var forums = scrInc.getReadableForums();

 

 

Access Analyzer is giving accurate results on the table and record level for the sn_communities_forum table. Can't figure out how it's doing that.

Any insight/help is highly appreciated. 

1 REPLY 1

Akash4
Kilo Sage

Hello Rachit,

Here is a sample script you can use.

The final JSON can be used to extract Forum details - it contains id, name,  availableForMembership, isAdmin, isModerator.

 

var siCall= new sn_communities.CommunityUserImpl();
var readForums= siCall.getReadableForums(); //returns Object based on Logged in user roles
var canReadJSON = JSON.stringify(readForums);
gs.print(canReadJSON );
var output = canReadJSON;

 

Output of above script is as follows in my PDI:

 

Output *** Script: [{"id":"ddee4b5183e7c210da36c2d6feaad384","name":"Security","availableForMembership":"0","isAdmin":false,"isModerator":true,"order":"20"},{"id":"19de0f9183e7c210da36c2d6feaad300","name":"Developer","availableForMembership":"1","isAdmin":false,"isModerator":true,"order":"10"}]

 

 Hope this helps!
Regards, Akash
_____________________________________________________________________________
Please mark it as helpful👍 or Accept Solution✔️ based on the response to your query.

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.