The Zurich release has arrived! Interested in new features and functionalities? Click here for more

trying to configure same UI action for three different views of the same table

Prasad49
Tera Contributor

Hi experts,

 

i am trying to configure same UI action for three different views of the same table, below is the script that i am trying with but its not working 

(function executeAction(sysIds, table) {
    var gr = new GlideRecord(table);

    for (var i = 0; i < sysIds.length; i++) {
        if (gr.get(sysIds[i])) {

       
            if (gr.u_state_a == 'draft') {
                gr.u_state_a = 'pending_for_approval';
            }
      
            else if (gr.u_state_b == 'draft') {
                gr.u_state_b= 'pending_for_approval';
            }
       
            else if (gr.u_state_c == 'draft') {
                gr.u_state_c = 'pending_for_approval';
            }

            gr.update();
        }
    }
    gs.addInfoMessage("Selected records sent for approval.");

Business Requirement

I have three different list views (View A, View B, and View C) for the same table sn_grc_profile.

Each view shows different fields (X, Y, Z). The process is:

  1. A user fills out the fields in a view (for example, field X in View A).

  2. The user selects records in the list view and clicks Send for Approval.

  3. A reviewer (checker) goes to the same view, reviews the records, and clicks Approve (or Reject) from the list view.

Currently, I created three separate buttons for each action: Send for Approval, Approve, Reject.

My challenge is that I want to reuse the same UI Action button across all three views.

  • Example: one Approve button should work for all three views (instead of having 3 separate Approve buttons).

  • Same goes for Reject and Send for Approval.

Also, the requirement is that users should be able to update multiple records directly from the list view using these buttons.



requesting for support on the issue, thanks in advance.
11 REPLIES 11

@Prasad49 

in the List Choice UI action you possibly won't know from which view the button is getting clicked.

try to see and use this in server side code of that UI action and see if you can get to know the view name from URL

var isViewA = gs.action.getGlideURI().toString().indexOf('View A Name') > -1;

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 Bawiskar ,
I don't need to get the view that I am currently in, I need to use a script to validate the state of the record that I have selected if its in draft it should be moved to pending for approval, as this same is UI action for the other views as well so just validation in the script is enough  if it's of X field and state is draft , il send it for approval by clicking on the request for approval. button should be able update the record state.

@Prasad49 

when you use list choice UI action you can get the sysIds selected using this

g_list.getChecked()

Then use GlideAjax and send the sysIds and then check state of each record by querying and then update the state.

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

Dhana3
Kilo Sage

Hi @Prasad49 ,

 

I think you can control the visibility of the UI action using the related list shown below. You need to specify the view and whether the button should be included or excluded. There won't be a need to make changes in the script or create multiple buttons.

Dhana3_0-1758553362804.png

 

Prasad49
Tera Contributor

Hi @Dhana,

 

Thanks for your kind response am trying to use Ui action button to update record which checks the current state of the record in the list view and update it when Ui action button is clicked.