Run List UI Action only once

Benedikt M_ller
Giga Contributor

Hello ServiceNow Community,

we have a List UI action that prints a label with QR code on a Zebra printer for all selected CIs. As fas as i know, a List UI action runs for each selected row. So if i select 10 rows, the ui actions runs 10 times.

I would like to customize the UI Action so that it is executed only once, regardless of the number of rows selected.

We want to print the labels in a definite order during mass printing actions. Therefore, the UI action should only run once, collecting the sys_id's of the selected rows, and then print the labels ordered by the serial number.

I have not found a solution for this yet. Is there a way to change this behavior for list ui actions?

Kind regards,

Benedikt

2 REPLIES 2

Community Alums
Not applicable

Hi @Benedikt Müller ,

Here is your solution :https://community.servicenow.com/community?id=community_question&sys_id=32000721db98dbc01dcaf3231f96...

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

prashantdharne
Tera Contributor

Hi @Benedikt M_ller ,

I found a solution for this. I looked everywhere and could not find a solution. So I built a neat hack to fix this.

 

Once we check the records, the entire script will run for the number of records we have checked. That you cannot avoid. But what you can do is force the code which you want to run just once. In my eg: I wanted to pass the list of SysID to a script without calling the script N number of times. So here is the solution:


Basically to run the code just once, all we need to do is to make sure that it runs once. You could also just run it for the first element or the last. So instead of doing extra array calculation which I am doing below, just compare it with the first element in the array. Hopefully this makes sense. It works for me. Let me know if this works or doesnt work for yall

 

var parentSysId = glideURI.get('sysparm_checked_items'); // Get the SysID of all the checked records

var sysIDString = parentSysId.split(','); // Create an array of the SysID


// Minus 1 from the lenght of the array. What we are trying to do is get the last element from the array

var arrMax = sysIDString.length - 1; 

 

//Check if the current record, is the last record. If it is, then run the logic

 

if (current.sys_id == sysIDString[arrMax]) {
gs.info('I am now ready to run');

}