Make a Field Mandatory when user clicks on Retire Button for Knowledge Articles in Workspace

21121A3359
Tera Expert
 
4 REPLIES 4

yashkamde
Mega Sage

Hello @21121A3359 ,

 

In your UI Action Add this script :

function onClick() {
    var mandatoryField = g_form.getValue('u_retire_reason');
    if (!mandatoryField) {
        g_form.showFieldMsg('u_retire_reason', 'Please provide a reason before retiring.', 'error');
        return false; // Prevent Retire action
    }
    return true;
}

 

If my response helped mark as helpful and accept the solution.

@yashkamde 
No not working can you please share output if you got it ?

yashkamde
Mega Sage

can you plz share the code where you use this and what's error getting?

Tanushree Maiti
Tera Patron

Hi @21121A3359 

 

Try this - updating Retire UI Action:

 

Navigate to System Definition > UI Actions.

Search for the global Retire UI action that applies to the Knowledge Article [kb_knowledge] table.

Ensure Client is checked.

In the Onclick field, enter runRetireAction()


function runRetireAction() {

        var retireField = g_form.getValue('your_field_name');//Replace 'your_field_name' with your actual field

    if (!retireField) {

          g_form.showFieldMsg('your_field_name', 'Please provide a reason before retiring.', 'error');

        return false;

    }

    g_form.setMandatory('your_field_name', true);

    gsftSubmit(null, g_form.getFormElement(), 'sysverb_update');

}

if (typeof window == 'undefined') {

    retireKnowledgeArticle();

}

function retireKnowledgeArticle() {

    current.workflow_state = 'retired';

    current.update();

}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti