The CreatorCon Call for Content is officially open! Get started here.

Hide retire button Knowledge article based on user.

nivethika
Tera Contributor

In the knowledge base table there is custom field with reference to group table

nivethika_0-1750742554737.png

Only user belongs to this group can retire this specific knowledge articles attached to this KB.

If the user not belongs to this group should not retire i/e retire button should be invisible for them in kb article form.

 

How can i achieve this please help me to find the solution.

 

10 REPLIES 10

Bhavya11
Kilo Patron
Kilo Patron

Hi @nivethika ,

 

Navigate to the Retire ui action and add the condition to it gs.getUser().isMemberOf('group1') // pass your group name instead of group1

 

 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,

BK

 

Ankur Bawiskar
Tera Patron
Tera Patron

@nivethika 

you can use this logic in the Retire UI button condition

OR

I will suggest you can avoid updating the OOTB UI action and use before update business rule and then stop user from retiring

BR Condition: State Changes To Retired

Script:

if (current.kb_knowledge_base.customFieldName != '' && !gs.getUser().isMemberOf(current.kb_knowledge_base.customFieldName)) {
    current.setAbortAction(true);
    gs.addErrorMessage('You are not member of group');
}

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

Thank you @Ankur Bawiskar,

Your logic i tried it worked well, but i need to hide the Retire ui action itself so that we can block the user not belong to that group to do retire

@nivethika 

the UI action condition field is with max length 254 so you will have to use script include to include that long condition

For Example: this UI action, do this for others as well

Before: 

AnkurBawiskar_0-1750746847188.png

 

After:

var RetireButtonVisibility = Class.create();
RetireButtonVisibility.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkRetireCondition: function(current) {
		// if custom field on KB base is empty then use OOTB condition
        if (current.kb_knowledge_base.customFieldName == '')
            return !(new KBCommon().isStackNameDialog()) && (new KBKnowledge().canRetire(current)) && (new KBCommon().canProvideReplacementArticle()) && (current.sys_class_name != 'kb_knowledge_block')
        else // if not then add your extra condition for group check
            return !(new KBCommon().isStackNameDialog()) && (new KBKnowledge().canRetire(current)) && (new KBCommon().canProvideReplacementArticle()) && (current.sys_class_name != 'kb_knowledge_block') && (gs.getUser().isMemberOf(current.kb_knowledge_base.customFieldName))
    },

    type: 'RetireButtonVisibility'
});

AnkurBawiskar_1-1750747003892.png

 

Add this in UI action condition: new RetireButtonVisibility().checkRetireCondition(current)

AnkurBawiskar_2-1750747057412.png

 

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