🌐 VARIABLE MANAGEMENT

Working with Global Variables, Power Fx, and Topic Inputs/Outputs

This section dives deep into variable management in Copilot Studio, covering global variables for seamless data sharing, Power Fx formulas for dynamic logic and complex expressions, and topic input/output parameters for collecting, validating, and passing information between topics.

By combining these features, you can build intelligent, context-aware conversational agents that remember user inputs, perform calculations, validate responses, and generate personalized messagesβ€”enabling smarter, more interactive, and seamless conversation flows.

πŸ”Ή What Are Global Variables?

Variables store user responses during a conversation. For example, when a user provides their name, you might store it in a variable like UserName.

By default, variables are topic-scoped, meaning they can only be used within the topic where they were created.

But what if you want to reuse that data across multiple topics?

πŸ‘‰ That’s where global variables come in.

  • Are accessible across all topics
  • Persist throughout the entire user session
  • Can also be set from external systems

πŸ” Why Use Global Variables?

Imagine this flow:

  • A Welcome topic collects the user’s name and email
  • An Appointment Booking topic needs that same information

Without global variables, you'd need to ask again ❌
With global variables, the agent already remembers βœ…

πŸ› οΈ How to Create a Global Variable

You don’t create a global variable from scratchβ€”you convert a topic variable into a global one.

  • Create or select an existing variable
  • Open the Variable properties panel
  • Change scope to: Global (any topic can access)
  • Save the topic

Once done: The variable gets a prefix: Global. (Example: UserName β†’ Global.UserName)

πŸ“ Note: The name of a global variable must be unique across all topics.
πŸ’¬ Using Global Variables in Topics

You can use global variables in Message nodes and Question nodes by selecting the {x} variable picker.

  • Go to Custom tab
  • Select your global variable
  • Variables are sorted alphabetically
πŸ” Tracking Where Variables Are Used
  • Select the global variable
  • Open Variable properties
  • Click View all references
  • Navigate directly to topics

❌ Deleting Global Variables

  • References become β€œUnknown”
  • Affected nodes may stop working
  • Topics may break
⚠️ Important: Before publishing your agent, fix or remove all broken references to deleted variables.
πŸ”„ Lifecycle of Global Variables
  • Persist for the entire session
  • Reset when session ends
  • Reset via β€œStart over” or Reset Conversation
  • Use Clear variable values node to reset manually
πŸ”— Setting Global Variables from External Sources

Useful for logged-in users and CRM integrations like Dynamics 365.

Example: Pass user name and greet instantly.

⏱️ Timeout Configuration

  • Recommended: 10 seconds (10,000 ms)
  • Provide default value if timeout occurs
Text("")
πŸ“ Note: IVR agents in Dynamics 365 Contact Center don’t support timeout values.
⚠️ Important: If your agent sets a variable internally, that value overrides any external value.
🌍 Passing Global Variables via URL
botURL?variableName=value
https://web.powerva.microsoft.com/webchat/bots/12345?UserName=Ana
  • Remove Global. prefix
  • Case-insensitive
πŸ’» Using Global Variables in Custom Canvas
dispatch({
  type: "WEB_CHAT/SEND_EVENT",
  payload: {
    name: "pvaSetContext",
    value: {
      "UserName": "Ana"
    }
  }
});
            

πŸ” Authentication-Based Global Variables

Depending on your authentication setup, Copilot Studio provides predefined global variables for personalization and secure interactions.

βœ… Key Takeaways

  • Global variables allow data reuse across topics
  • Improve user experience by avoiding repeated questions
  • Can be set internally or externally
  • Proper management avoids broken flows

βš™οΈ Create Expressions using Power Fx

Power Fx is a low-code language that uses Excel-like formulas. Use Power Fx to create complex logic that allows your agents to manipulate data. For instance, a Power Fx formula can set the value of a variable, parse a string, or use an expression in a condition.

πŸ“ Note: Power Fx formulas in Copilot Studio use US-style numbering. That is, the decimal separator is a period or dot, as in 12,567.892. This means you must use commas (,) as parameter separators for your Power Fx formulas.

πŸ“Œ Prerequisites

  • Create and edit topics
  • Variables overview

πŸ”€ Use Variables in a Formula

To use a variable in a Power Fx formula, you must add a prefix to indicate its scope:

  • System variables β†’ System.
  • Global variables β†’ Global.
  • Topic variables β†’ Topic.
  • Environment variables β†’ Environment.

Example: System.Conversation.Id

πŸ”’ Use Literal Values in a Formula

You can also use literal values in formulas. Ensure they match the correct data type format:

  • String: "hi", "hello world!", "copilot"
  • Boolean: true, false
  • Number: 1, 532, 5.258, -9201
  • Record/Table: [1], ["cats","dogs"], { id: 1 }
  • DateTime: Time(5,0,23), Date(2022,5,24)
  • Blank: Blank()

Choice: Not supported

πŸ“Š Common Power Fx Formulas

  • String: Text, Concat, Len, Lower, Upper, Proper
  • IsMatch, Match, EndsWith, StartsWith, Find
  • Replace, Substitute
  • Boolean: And, Or, Not, If, Switch
  • Number: Round, Int, Value, Trunc
  • Record/Table: Filter, LookUp, Count, JSON
  • DateTime: Now, Today, DateAdd, DateDiff
  • Blank: Coalesce, IsBlank, IsError

πŸ§ͺ Use Power Fx to Set a Variable

This example stores and outputs the customer's name in capital letters.

  • Ask: "What is your name?"
  • Save response as customerName
  • Create variable capsName
  • Use formula:
Upper(Text(Topic.customerName))

Then display: HELLO {capsName}

πŸ” Use Power Fx as a Condition

Example: Check if a booking date qualifies for a discount (14+ days in advance).

  • Ask: "Booking date?"
  • Save as bookingDate
  • Use condition formula:
Topic.bookingDate > (DateAdd (Now(), 14))
  • If true β†’ "You qualify for a discount."
  • Else β†’ "Sorry, you don't qualify for a discount."

πŸ”§ Manage Topic Inputs and Outputs

Topics in Copilot Studio can have input and output parameters. When a topic redirects to another topic, these parameters allow information to be passed between topics seamlessly.

If your agent uses generative orchestration, it can automatically fill input parameters using conversation context or generate questions to collect values from the user. Similarly, outputs can be used to generate contextual responses without configuring verbatim messages within the topic.

Topic inputs and outputs can share values with other topics and actions within the same generated plan, enabling a consistent flow of information.

βž• Add Inputs and Outputs

To add inputs or outputs for a topic:

  • Select Details in the navigation bar on the authoring canvas, or from the context menu on the Topics list page.
  • Navigate to the Inputs or Outputs tab.
  • Create new input or output variables by selecting Create a new variable.
  • For each variable, enter a name, data type, and description.
βš™οΈ Configure How Inputs Are Filled

For agents using generative AI, additional properties are available for input variables under How will the agent fill this input?:

  • Dynamically fill with the best option: The agent attempts to populate the value from context or previous messages, generating a question if no value is found.
  • Set as a value: Override the input with a literal value, an existing variable, or a Power Fx formula.

Ensure the correct type of value is captured by specifying an entity type under Identify as.

πŸ“ Additional Input Settings

Inputs have properties to control agent behavior:

  • Should prompt user: Determines if the agent should attempt to fill the variable before executing the topic. Enabled by default.

These settings ensure the agent collects the right type of value and validates responses effectively.

βš™οΈ Additional Settings for Inputs of Topics and Actions

When configuring inputs for topics or actions, additional settings allow you to control how your agent gathers input and validates responses.

❗ Important: These additional settings are always available for action input parameters. For topic input parameters, they are available only if your agent is configured to use generative orchestration.
✏️ Customize How the Agent Prompts Users

By default, the agent uses the name and description of input parameters to automatically generate questions for missing information. You can override this behavior:

  • Select Customize under Prompt.
  • Enter your own question, which can include references to variables or Power Fx formulas.
πŸ” Configure Reprompt Behavior

By default, agents repeat a question up to two times if the user provides an invalid answer. Options include:

  • How many reprompts: Repeat up to 2 times (default), Repeat once, or Don't repeat.
  • Retry prompt: Customize the question to ask again if validation fails, e.g., "What is the ID? It should be a number."
βœ”οΈ Additional Entity Validation

Responses are validated based on the entity selected in Identify As. You can add extra validation:

  • Condition: Enter a Power Fx formula that returns true or false, e.g., Topic.Var1 < 10.
  • Condition not met prompt: Customize the question when the condition fails, e.g., "What is the ID? It should be a number less than 10."
❌ No Valid Entity Found

Determines what happens when the agent cannot get a valid response after maximum retries:

  • Escalate: Redirect to the Escalate system topic (default).
  • Set variable to value: Assign a default value and continue to the next node.
  • Set variable to empty: Clear the variable and move to the next node; later nodes can check if a value exists.
  • No entity found message: Customize a message shown to the user, e.g., "Looks like you're struggling. I'm redirecting you to someone on our team."

πŸ“Œ Final Thoughts

🌐 Global Variables

Enable seamless data sharing across topics, helping your agent remember user inputs and maintain context throughout the conversation.

⚑ Power Fx Formulas

Allow dynamic logic, complex condition evaluation, and data manipulation for smarter decision-making within conversations.

πŸ›  Topic Inputs & Outputs

Ensure accurate data capture, validate responses, configure prompts, and control reprompt behavior for a smooth, context-aware user experience.

Combining these elements allows you to create conversational agents that are intelligent, responsive, and personalized, reducing repetitive questions and optimizing interaction flows. Explore advanced patterns to make your agent truly context-aware and user-friendly.