Count items in a collection or array function

The “Count Collection” action retrieves a count of the number of items in an existing collection or array object.

Decision branches in workflows often require logical tests for certain conditions before proceeding. An action that extracts strings of text from a collection may fail if there are no items to extract, so the process designer may want to first validate that the collection is not empty before attempting to take any further action. The “Count Collection” action in PowerTools makes this possible by analyzing the collection and providing a count of the items within it. 

For example, an array of strings such as “keys”, “wallet”, “phone”, “hat”, “umbrella” would return a value of 5. The data type of the array elements has no bearing on the count of items. This action can be useful as part of a process that first verifies if an array contains a certain number of elements (i.e. more than zero) before proceeding with other array operations in order to avoid errors or unnecessary processing on empty arrays.

Parameters

TitleNameTypeDescription
CollectioninputarrayCollection of items to count

Response

Status

TitleNameTypeDescription

Success

Result

result

number

Item count

Failure

Result

result

string

Error description

Integrate the "Count Collection" function into a workflow or app with the platform of your choice:

How to count items in a collection (array) in Microsoft Power Automate

Instructions

  1. In the Flow designer, click the “+” icon to insert a new action.
  2. Select the “Collections – Count Collection” action under PowerTools in the “Choose an operation” dialog.
  3. Insert the necessary values or variables in each input field.
  4. Execute the flow.

Example

Create a workflow to count a collection in Microsoft Power Automate

Video

How to count items in a collection (array) in Microsoft Power Apps

Instructions

  1. Add the PowerTools connector from the Data menu.
  2. In the formula for the control, variable or element, type “ApptigentPowerTools.CountCollection().result”. Within the parentheses, enter the field, control or variable that contains the source collection.
  3. Preview or run the app.

Example

Video

How to count items in a collection (array) in Salesforce

Instructions

  1. Drag and drop a new action onto the design surface. Edit the action and choose PowerTools from the category menu on the left.
  2. Click in the “Action” search box, scroll through the action list and choose “Collections – Count Collection”.  Insert the necessary values or variables in each input field.  (Note: Click the “Advanced” link to manually assign output variables to the action results)
  3. Run or Debug your flow to preview the results.

Example

Video

How to count items in a collection (array) in Nintex

Instructions

  1. Locate the “Apptigent PowerTools” group in the actions navigator then drag and drop the “Collections – Count Collection” action onto the design surface.
  2. Insert the necessary values or variables in each input field.
  3. Assign the result to a variable.
  4. Test the workflow.

Example

[Insert Image]

Video

How to count items in a collection (array) in another Platform or Custom Code

Instructions

If your platform is not listed and it supports Open API (Swagger) extensions, import the API Definition document from the Developer Edition product on our Customer Portal at https://portal.apptigent.com/product (look for the Open API link at the top of the PowerTools Developer API definition page). Invoke the desired actions in your app or workflow design tool, supplying values for the listed parameters. Refer to the developer documentation on the Customer Portal for details on input and output formats.

If you are developing a custom app, execute a RESTful POST operation to the /CountCollection endpoint in your application code or use the pre-generated client scaffolding from our Github repo at https://github.com/apptigent/powertools. Be sure to include your API Key (Client ID) in the header using the “X-IBM-Client-Id” key/value pair. The body should be a well-formed JSON object with the parameter label(s) and value(s) in the specified format. Refer to the API documentation at https://portal.apptigent.com for more information.

Example

const request = require('request');

const options = {
  method: 'POST',
  url: 'https://connect.apptigent.com/api/utilities/CountCollection',
  headers: {
    'X-IBM-Client-Id': 'REPLACE_THIS_KEY',
    'content-type': 'application/json',
    accept: 'application/json'
  },
  body: {input: ['a', 'd', 'c', 'b', 'e']},
  json: true
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});