Use Case: Save Data After Iterating on Invoices

In this use case, an organization 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 identifies the invoice numbers to cancel by generating a report.

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. However, an integration can't perform this task. Here's why: The REST APIs for the application don't allow you to select 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
    • Type: string

    • Not a collection

Define the data type for the output

  • Name: Result

  • Properties:

    • InvoiceNumber
      • Type: string

      • Not a collection

    • Status
      • Type: string

      • Not a collection

See Create a Data Type.

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 an integration. 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 collects information for multiple invoices, so it must be a collection.

The output allows the robot to collect the following information and pass it back to an integration:

  • The invoice number of each canceled invoice.

  • The status of each canceled invoice.

See Create a Trigger's Input or Output.

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

See Create a Variable.

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

See Add a Foreach Loop and Add a Data Stitch Action.

Define the details of the data stitch

The data stitch 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.

See Add a Data Stitch Action.