Lab #4: SAP Concur - Lookup and Create Expense Reports

In addition, add an expense item to an existing report

Refer to the legend to help complete this guide.

Scenario

In this case we will build the ability for a user to create a new expense report, look up existing expense reports, and also add an expense item to an expense report, all without having to login to Concur.

NOTE: You are provided a SAP Concur Sandbox instance in order to do this. You see an "SAP Concur" connector in Creator Studio that has already been setup to make API calls. You will also be granted a login to the SAP Concur instance in the Microsoft Apps Portal indicated by this icon.

Steps

We will need to build 4 different actions altogether in order to make this work.

📘

Visit the Developer Legend for details on how to make the following API requests.

👉 https://help.moveworks.com/docs/moveworks-developer-legend


📘

We will be using Script Actions here - so check out our APIThon documentation!

👉 https://help.moveworks.com/docs/apithon-a-special-kind-of-python

  1. Build the "Get Expense Reports" API endpoint using the curl command in the Developer Legend

    Note: You'll need to "MAP" through each report as this returns an array. Refer to this syntax below for reference:

    - return:
          output_mapper:
            results:
              MAP():
                converter:
                  current_amount: item.Total
                  status: item.ApprovalStatusName
                  id: item.ID
                  created: item.CreateDate
                  name: item.Name
                items: data.get_expense_reports_sap_concur_result.Items
    
  2. Get User By ID - Since the "Create Expense Report" API endpoint requires a SAP Concur User ID in order to complete the action, this will be necessary.

  3. Create Expense report - refer to the legend for the cURL

    Note: If successful, you will get a URI back from the POST. Notice that the last parameter of that URL is the Report ID of the report that was just created. We can extract that and map it so that Moveworks has context of the Report ID even after it was created. See a sample syntax below - here we are using "Script Actions"

      - script:
          output_key: report_id
          input_args:
            expense_code: data.create_expense_report_sap_concur_result.uri
          code: |
            
            expense_code.split('/')[-1]
      - return:
          output_mapper:
            id: data.report_id
    
  4. Add expense item to expense report - refer to legend for the cURL

    NOTE: There is an interesting scenario where the expense code has to be a 5 digit code that a user might not refer to in this way. In addition, the API expects the date to be in the format "YYYY-MM-DD" which the user will also probably not say. We can accomplish this with a combination of prompts and script actions in order to accomplish this.

    In the "Description" of your Input Variables of the Compound Action is where we can do this.
    For the date, try a prompt like "Reformat the date you receive into the format of of YYYY-MM-DD"
    For expense code, try a prompt like "Takes in either Hotel, Business Meals, Train, Internet or Miscellaneous"


This will allow Moveworks to guide the user on what options they have for expense type, while also preserving the date format automatically.

Once we've gathered the expense type, you can write a script action to enforce the preservation of the expense code in a format the API requires. See below:

- script:
      output_key: code
      input_args:
        expense_code: data.expense_code
      code: |
        # Hotel, Business Meals, Train, Internet or Miscellaneous
        if 'Hotel' in expense_code:
          return_code = 'LODNG'
        elif 'Business Meals' in expense_code:
          return_code = 'BUSML'
        elif 'Train' in expense_code:
          return_code = 'TRAIN'
        elif 'Internet' in expense_code:
          return_code = 'ONLIN'
        else:
          return_code = 'MISCL'

        return_code