Allow only article author to edit articles

DylanB
Tera Guru

Hello, we are exploring the idea of changing our knowledge articles so that only the article's author can edit their articles (and Knowledge Managers, etc). Has anyone done this before? If so, how did you restrict specific article edit access to the author?

 

I do see the arguments against changing this also though, as it could affect collaboration and complicate processes unnecessarily. 

1 ACCEPTED SOLUTION

Hi @DylanB ,

Sure, I can't share the exact code, but I can share a different approach, using Business Rules and onLoad Client script. Follow along,

 

1. Business Rule: To prevent update of article from backend if the user is not the author, create a business rule like the one below.

AnveshKumarM_0-1679480688787.png

AnveshKumarM_1-1679480715202.png

 

2. Display Business Rule: To make the author of the article available to onLoad Client Script, Write a display business rule like the one below and use g_scratchpad to set the author.

AnveshKumarM_3-1679480830421.png

 

AnveshKumarM_4-1679480846347.png

 

3. onLoad Client Script: To disable the article fields for editing, write a client script like the one below.

AnveshKumarM_5-1679480910295.png

 

function onLoad() {
    if (g_form.isNewRecord()) {
        return;
    }
	if(g_scratchpad.kb_author_name != g_user.userID){
		g_form.addErrorMessage('You are not the author of this article.');
		g_form.setReadOnly('text', true);
		g_form.setReadOnly('short_description', true);
	}
}

 

That's it!!!

 

Please Accept my Answer as Solution, if it helped in solving your issue.

 

Thanks,

Anvesh

 

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

Hi @DylanB,

Recently we did similar one using a Before Update Business rule. We just check if the current user is not the actual author Abort the action and display the error message.

 

And, an onLoad client script which will call a Client Callable script include using GlideAjax to check if the current user is the actual author or not and and display a message saying the same and disable the fields for editing.

So we are restricting both ways, front end and backend.

Let me know if you need any more inputs for this approach.

 

Thanks,

Anvesh

Thanks,
Anvesh

Hi Anvesh, would you be willing to share the scripts you're using for that?

Hi @DylanB ,

Sure, I can't share the exact code, but I can share a different approach, using Business Rules and onLoad Client script. Follow along,

 

1. Business Rule: To prevent update of article from backend if the user is not the author, create a business rule like the one below.

AnveshKumarM_0-1679480688787.png

AnveshKumarM_1-1679480715202.png

 

2. Display Business Rule: To make the author of the article available to onLoad Client Script, Write a display business rule like the one below and use g_scratchpad to set the author.

AnveshKumarM_3-1679480830421.png

 

AnveshKumarM_4-1679480846347.png

 

3. onLoad Client Script: To disable the article fields for editing, write a client script like the one below.

AnveshKumarM_5-1679480910295.png

 

function onLoad() {
    if (g_form.isNewRecord()) {
        return;
    }
	if(g_scratchpad.kb_author_name != g_user.userID){
		g_form.addErrorMessage('You are not the author of this article.');
		g_form.setReadOnly('text', true);
		g_form.setReadOnly('short_description', true);
	}
}

 

That's it!!!

 

Please Accept my Answer as Solution, if it helped in solving your issue.

 

Thanks,

Anvesh

 

Thanks,
Anvesh

Hi Anvesh, that is very helpful! Thank you!