Pre-General Availability: 2024-09-02

Use Case: Save Data After Iterating

A robot must manually cancel a set of invoices and obtain the invoice number and status for each invoice. Explore how a foreach loop and the data stitch action support this workflow.

Scenario

You must periodically cancel a number of invoices. An integration generates a report that finds the invoices that need canceling. The report provides the invoice numbers of the invoices that need canceling in an XML response.

The robot completes the following tasks:

  • Cancels a set of invoices one by one.

  • Obtains the invoice number and status for each canceled invoice.

This use case focuses on how you use the data stitch action to obtain the invoice number and status from each invoice. For information about how to update a set of invoices, see Use Case: Update a Set of Invoices.

Why Create a Robot?

An integration provides improved scalability over a robot for work like this, but you cannot design an integration to cancel the invoices. Here's why: The REST APIs for the application don't allow you to select only invoices of a specific type, and you must cancel invoices with a specific invoice type. Therefore, a robot is the ideal solution for automating this manual, repetitive task.

Workflow

Requirement How to meet the requirement

Create the data types for the trigger

Define the data type for the input:

  • Name: InvoiceNumber

  • Property: Invoice, of type string, not a collection

Define the data type for the output:

  • Name: Result

  • Properties:

    • InvoiceNumber, of type string, not a collection

    • Status, of type string, not a collection

Define the trigger

Define the trigger's input:

  • Name: InvoiceNumber
  • Type: InvoiceNumber
  • Collection: Yes

The input allows the robot to receive a list of invoices from the integration that calls the robot. For example, the robot might receive the invoice numbers for 20 invoices.

Define the trigger's output:

  • Name: Status
  • Type: Result
  • Collection: Yes

The output allows the robot to collect the following information so that it can pass the information back to the integration:

  • The invoice number of each canceled invoice.

  • The status of each canceled invoice.

The output collects information for multiple invoices, so it must be a collection.

Define the variables

Define a variable to hold the number of each updated invoice:

  • Name: CurrInvoice
  • Type: InvoiceNumber
  • Collection: No

Define a variable to hold the status of each updated invoice:

  • Name: CurrentInvoiceResult
  • Type: Result
  • Collection: No

Within the robot, add a foreach loop and a data stitch action within it

When a robot must perform the same work on multiple items, define the robots actions in a foreach loop.

This use case is focused on the tasks that you perform in the data stitch and doesn't provide details about all of the actions in the foreach loop. For a use case that focuses on how to update a set of invoices, see Use Case: Update a Set of Invoices.

The foreach loop might look something like this:

The foreach loop contains many robot actions, including the data stitch action, which is the last action

Define the details of the data stitch

The following foreach loop contains the following operations:

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

  • First operation: Assign a value

    ${$VARIABLE.CurrentInvoiceResult[InvoiceNumber]}

    = ${$VARIABLE.CurrInvoice[Invoice]}

    The foreach loop cancels each invoice, one at a time. This assignment loads the invoice number for each canceled invoice to the InvoiceNumber object in the CurrentInvoiceResult variable.

    Because each iteration of the foreach loop loads a new invoice number, the InvoiceNumber object in the CurrentInvoiceResult variable holds each invoice number only temporarily. The third operation in the data stitch records the value permanently.

  • Second operation: Assign a value

    ${$VARIABLE.CurrentInvoiceResult[Status]}

    = "Success"

    This assignment assigns the Success value for each canceled invoice to the Status object in the CurrentInvoiceResult variable.

    Because each iteration of the foreach loop loads a new status, the Status object in the CurrentInvoiceResult variable holds each status only temporarily. Another operation in the data stitch records the value permanently.

  • Third operation: Append a value

    ${$OUTPUT.Status} +

    ${$VARIABLE.CurrentInvoiceResult}

    This assignment appends the two objects in the CurrentInvoiceResult property, InvoiceNumber and Status, to the Status output. Because this operation is an append, the operation records all values for all invoices to the output.