Use Case: Save Values After Iterating on a Table

In this use case, an organization must save values from a table. Explore how the define web table action, data stitch action, and a foreach loop support this workflow.

Scenario

A robot completes the following tasks:

  • Opens a dashboard, and views all invoices that have been placed on hold.

  • Collects the following information for all on-hold invoices:

    • Invoice number

    • Hold reason

    • Invoice amount

Why Create a Robot?

An API is unable to capture the data from the table, or the team that is planning this automation work is unaware of the availability of an API that can do this work.

Workflow

Requirement How to meet the requirement

Create a data type for the trigger's output

  • Name: Result

  • Properties:

    • InvoiceNumber
      • Type: string

      • Not a collection

    • HoldReason
      • Type: string

      • Not a collection

    • InvoiceAmount
      • Type: string

      • Not a collection

The Result data type has 3 properties: InvoiceNumber, HoldReason, and InvoiceAmount

See Create a Data Type.

Define the trigger's output

  • Name: OnHoldInvoices

  • Type: Result

  • Collection: Yes

An output named OnHoldInvoices is of the Result data type and is a collection

The output allows the robot to collect the invoice number, hold reason, and invoice amount for each on-hold invoice and pass this information back to the integration.

See Create a Trigger's Input or Output.

Define the variables

Define a variable to hold each invoice number, hold reason, and invoice amount

  • Name: CurrentInvoiceInfo

  • Type: Result

  • Collection: No

Because this variable is of the Result data type, it has three properties:

  • InvoiceNumber

  • HoldReason

  • InvoiceAmount

These properties hold the required data from the on-hold invoices. This variable collects the values obtained by the get text action. This variable also sends the values to the output using a data stitch action.

The CurrentInvoiceInfo variable is of the Result data type

See Create a Variable.

Identify the columns that contain the data that you need

Add a define web table action, and target the columns that contain the data that you need.

After you finish identifying the columns, the action looks similar to this:

The Define Web Table panel specifies three columns from a table

See Add a Web Table Action.

Add a foreach loop so that you can iterate over the XPath locators in the table

Add a foreach loop to the robot.

With the define web table action, you identify the XPath locators that you're interested in. The foreach loop allows you to iterate over these locators.

  • For the Collection field, select the variable that the define web table action created for you.

  • For the Iteration parameter field, enter a name for every value in the table, such as item.

In the foreach panel, the Collection field contains the variable that was created for the define web table action. The entry in the Iteration parameter field is "item".

See Add a Foreach Loop.

Get text from the table

Overview

Within the foreach loop, add the following actions:

  1. Get text: Get the text from one cell in the first column you identified.

  2. Log: Record the text to the activity stream.

  3. Get text: Get the text from one cell in the second column you identified.

  4. Log: Record the text to the activity stream.

  5. Get text: Get the text from one cell in the third column you identified.

  6. Log: Record the text to the activity stream.

The first iteration of the foreach loop gets text from the first row in the table. The second iteration gets text from the second row in the table, and so on.

The canvas contains a foreach action, which contains the following actions in order: get text, log, get text, log, get text, and log

How to define the get text actions

  • On the Input tab for each get text action, for the Locator field, select the property for a column.

    In the Get Text panel, on the Input tab, the Locator field contains the property of a variable that the define web table action created

  • On the Output tab, for the Save to field, drag the appropriate property for the CurrentInvoiceInfo variable. For example:

    • Use InvoiceNumber for the first get text action.

    • Use HoldReason for the second get text action.

    • Use InvoiceAmount for the third get text action.

    In the Get Text panel, on the Output tab, the Save to field contains ${$VARIABLE.CurrentInvoiceInfo[InvoiceNumber]}, which is the value for the InvoiceNumber property of the CurrentInvoiceInfo variable

How to define the log actions

For each log action, in the Message field, drag the appropriate property for the CurrentInvoiceInfo variable. For example:

  • Use InvoiceNumber for the first log action.

  • Use HoldReason for the second log action.

  • Use InvoiceAmount for the third log action.

In the Log panel, the Message field contains ${$VARIABLE.CurrentInvoiceInfo[InvoiceNumber]}, which is the value of the InvoiceNumber property of the CurrentInvoiceInfo variable

See Add a Get Text Action and Add a Log Action.

Add a data stitch to the foreach loop, and define its details

The data stitch doesn't contain an assign operation because the get text action already inserted values into the properties of the placeholder variable (CurrentInvoiceInfo). Therefore, the data stitch contains only the following an append operation. This operation appends the CurrentInvoiceInfo variable to the OnHoldInvoices output. Because this operation is an append, the operation records all values for all on-hold invoices to the output.

${$OUTPUT.OnHoldInvoices} + ${$VARIABLE.CurrentInvoiceInfo}

The data stitch panel contains details about the data stitch. Its contents are described in the text in this section.

See Add a Data Stitch Action.