Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Create a Button in RITM Worknotes for a Specific Catalog Item with Conditional Visibility?

Vinusha928
Mega Explorer

Hello All,

I have a requirement where I need to add a custom button in the Worknotes section of an RITM (Requested Item) for a specific catalog item. The conditions are:

  • The button should only be visible after the associated task is completed.
  • When clicked, the button should navigate to a specific URL/link.

Could you please guide me on:

  1. The best approach to implement this (UI Action, Client Script, or any other method)?
  2. How to set the visibility condition based on the task completion status?
  3. Any examples or best practices for adding such buttons in RITM Worknotes?

Thank you in advance for your help!

2 REPLIES 2

Kieran Anson
Kilo Patron

Assuming you're referring to the classic UI, not workspaces, you won't be able to add a button into the main form. You'll have to choose one of the locations a UI action can appear via it's configuration. 

 

You'd use the condition field to determine whether to show the UI action based on the catalog item, and also query the child tasks to determine whether the taks desired is closed 

 

In terms of best practice - you shouldn't really be needing to work at the RITM level. The sc_tasks are the data records where actions are performed, and the RITM is a container. So you might already be diverging away from best practice 🙂

Anupam1
Mega Guru

Hi @Vinusha928 ,

 

Best Approach

  • UI Action is the right choice for adding a custom button in the RITM form (including the Worknotes section).
  • Client Script can be used in combination to control visibility dynamically (based on task completion).
  • Avoid hardcoding logic directly in the UI Action "Condition" field if you need complex checks — instead, use a scripted condition or a Client Script.

 

Step 1: Script Include (Server-side check)

Create a Script Include to check if tasks are completed for a given RITM.

var TaskCompletionCheck = Class.create();

TaskCompletionCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isTaskCompleted: function() {

        var ritmSysId = this.getParameter('sys_id');

        var gr = new GlideRecord('sc_task');

        gr.addQuery('request_item', ritmSysId);

        gr.addQuery('state', '3'); // 3 = Closed Complete (adjust if needed)

        gr.query();

        if (gr.hasNext()) {

            return 'true';

        }

        return 'false';

    }

});

  • Save this Script Include.
  • Make sure it’s Client Callable.

 

 

 Step 2: UI Action (Button)

Create a UI Action on the sc_req_item table.

  • Action type: Form button
  • Name: Go to Link
  • Condition: Leave blank (we’ll control visibility via Client Script).
  • OnClick Script:

function onClick() {

window.open("https:// your-target-url.com", '_blank');

}

 

Step 3: Client Script (Visibility Control)

Create an onLoad Client Script on the sc_req_item table.

function onLoad() {

    var ga = new GlideAjax('TaskCompletionCheck');

    ga.addParam('sys_id', g_form.getUniqueValue());

    ga.getXMLAnswer(function(response) {

        if (response === 'true') {

            g_form.showAction('go_to_link'); // sys_id or name of your UI Action

        } else {

            g_form.hideAction('go_to_link');

        }

    });

}

  • Replace 'go_to_link' with the Action name or sys_id of your UI Action.
  • This ensures the button only shows when the task is completed.

 

 Best Practices

  • Keep logic in Script Includes for reusability.
  • Use GlideAjax instead of GlideRecord in Client Scripts (better performance).
  • Test with multiple catalog items to confirm visibility works as expected.
  • Document the customization so future admins know why the button exists.

 

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

 

Thanks,

Anupam.