You do not have sufficient privileges to access this knowledge item message in SP

Harsha34
Tera Expert

Hi,

 

This is an OOB box behavior on Service Portal that--> if a non admin user has already opened an article that was not retired when opened, but this article got retired from the backend and when the non admin user reloads the page they get "You do not have sufficient privileges to access this knowledge item", same with the favorites or permalink URL as well. This is actually a misleading message that might confuse them with role issues. I want this message to change something for retired when the article gets retired. If they are not in a group then this message"You do not have privileges " is fine.

 

The OOB widget is --> Knowledge Article Content

 

For admins it does not show any message, it just shows retire beside the article number which is fine.

 

I tried this at line 198 but the knowledgeRecord is giving null data everytime for non admin user, it works somehow for admins, not able to understand why does not it work for non admin users.

.....................>

}
gs.addInfoMessage("Is Expired "+data.isArticleRetired);
 
if (knowledgeRecord && knowledgeRecord.getValue('workflow_state') === 'retired') {
                    data.messages.ARTICLE_RETIRED = gs.getMessage("This knowledge item has been retired");
 
                } else {
                    data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item");
                    data.messages.RECORD_NOT_FOUND = gs.getMessage("Knowledge record not found");
                }
 
Please help me find out how to fix this for both urls that is the main page or favorites or permalink (sys_id or sysparm_article).
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Harsha34 

since in backend the article has been retired and when user reloads the IF won't work due to ACL block

try this

-> Instead of using knowledgeRecord.getValue, check if knowledgeRecord is null. Then, use additional logic to determine whether it's due to retirement or other ACL issues.

// Server-side script in Knowledge Article Content widget
var sysId = $sp.getParameter("sys_id") || $sp.getParameter("sysparm_article");
var record = $sp.getRecord('kb_knowledge', sysId);
if (!record) {
  // Try to fetch with GlideRecord for fallback information
  var gr = new GlideRecord("kb_knowledge");
  if (gr.get(sysId)) {
    if (gr.getValue("workflow_state") == "retired") {
      data.messages.ARTICLE_RETIRED = gs.getMessage("This knowledge item has been retired");
    } else {
      data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item");
    }
  } else {
    data.messages.RECORD_NOT_FOUND = gs.getMessage("Knowledge record not found");
  }
} else {
  // Render as normal, with record available
}

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I tried something like this before but no luck, it works for admin but not for non amin.

data.isNotExpired = 'True';
//Our Logic
data.checkArticle = $sp.getParameter('sys_kb_id');
data.checkArticleNumber = $sp.getParameter('sysparm_article');
 
 
var grTest = new GlideRecord('kb_knowledge');
//if(data.checkArticle != null){
grTest.addEncodedQuery('sys_id=c8210e85fb00f6d0fa5bf5efaeefdcbd');
//}
//else{
//grKnowledge1.addQuery('number',data.checkArticleNumber);
//}
grTest.query();
gs.addInfoMessage("Article Retired1 "+grTest.getEncodedQuery());
if(grTest.next())
{
gs.addInfoMessage("Article Retired1.1 "+grTest.getValue("workflow_state"));
if(grTest.getValue('workflow_State') == 'retired'){
data.isNotExpired = 'False';
 
}
}
 
I tried hardcoding the sys of retired article as well but this is not entering in if Loop in table where workflow is retired, everytime it goes to else block and hence populate message "You do not have sufficient privileges".
 
Can you please try replicating at your end and try something in OOB widget if this works?

Nehal Dhuri
Mega Sage

Hello @Harsha34 

Use the following code in the else part at line no 198:

if(!kbViewModel.canAccessRetiredArticle(kbViewModel.knowledgeRecord)){
		data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("This article is retired");
}else{
		data.messages.INSUFFICIENT_PREVILEGES = gs.getMessage("You do not have sufficient privileges to access this knowledge item ");
		data.messages.RECORD_NOT_FOUND = gs.getMessage("Knowledge record not found");
}


Screenshot for reference:

NehalDhuri_2-1758115233013.png

 

 

NehalDhuri_1-1758115133231.png


Make sure that you have cloned the widget and replaced the original widget with cloned one.

 

Please hit like and mark my response as correct if that helps

Hey Nehal,

 

This code worked for retired articles but now it is overriding the existing message that was coming for those articles which cannot by access by someone which is "You do not have sufficient privileges".

 

Please suggest.

Thanks