Skip to main content

Assign Scripting Variable

This guide explains how to set up a logic hook in Botium to assign or update a scripting variable using a JSONPath expression extracted from the message content.

This logic hook sets or overwrites a variable from message content using a JSONPath Expression. It can be used only as a Bot Step.
Warning: Use this logic hook with care. If placed before the bot message, it will cause an error during testing.
Note:
  1. On the left navigation pane, head to Botium Tools & Settings > Test Sets > Your Test Set > Test Cases
  2. Click the + NEW button to add a new Convo, or select a previously created test case from the list.
  3. Add a new + BOT STEP
  4. Click the Edit icon, or anywhere inside the step, and search the list for the 'Assign Scripting Variable' logic hook.

  5. Configure the Logic Hook:
    1. Variable Name: Specify the name of the variable. Usually, start the variable name without "$". Use "$" only if you need logic hook argument replacement.
    2. JSONPath Expression: Enter the JSONPath expression to extract the desired content from the message.

  6. Click the APPLY CHANGES button to complete the step entry.

Example Convo:

Note:

Example Botium Script:

Extract a variable from a card:
#me
get invoice details for customer number 435643

#bot

CARDS INVOICE NUMBER
ASSIGN_SCRIPTING_MEMORY invoiceNumber|$.cards[0].content
Use the extracted variable in the next conversation step:
#me
get invoice due date for invoice number $invoiceNumber

#bot
invoice due date for invoice number $invoiceNumber is 02/12/2020
Explanation:
  • ASSIGN_SCRIPTING_MEMORY invoiceNumber|$.cards[0].content assigns the value extracted by the JSONPath expression $.cards[0].content to the variable invoiceNumber.
  • In the next step, the variable $invoiceNumber is used to request further information.

Was this article helpful?

0 out of 0 found this helpful