The types of variables available in Copilot Studio are almost the same as those in Power Apps (Power Fx). They are as follows:
String: Text
Bool: true or false
Number: Numeric values
Table: Tables (including arrays)
Record: Records (objects)
DateTime: Date and time
Choice: Options
Blank: Blank (same as blank in Power Apps)
Among these, the “Choice” type seems to differ from Power Apps. In Power Apps, table-type values were used as options in controls like combo boxes. However, in Copilot Studio, “Choice” is treated as a distinct type.
Additionally, entities themselves are not considered “types” but instead have their own defined types. These include:
“Age,” “Currency,” “Count,” etc.: Number type
“Postal Code,” “Country,” “City,” etc.: String type
“User-defined entities,” “Multi-select options,” etc.: Choice type
Next, let’s look at the types of variables. Copilot Studio provides the following four types of variables:
Topic Variables: Variables usable only within a single topic (minimum scope)
Global Variables: Variables accessible across all topics
System Variables: Variables managed by Copilot Studio, accessible in all topics
Environment Variables: Variables set at the Power Platform environment level, similar to those in Power Apps
Let’s examine their details and differences in behavior.
Variable Scope: Topic Variables vs. Global Variables
To compare topic variables and global variables, I set up two topics: “Calling Topic” and “Called Topic.”
In the “Calling Topic,” a topic variable is defined:
Along with a global variable:
When checking variables in the “Called Topic,” only the global variable is accessible. ※ Technically, it doesn’t have to be a “Called Topic”; all topics within the agent can access global variables.
When testing this setup, a global variable defined in the “Calling Topic” can be accessed from the “Called Topic” to display a message.
Global Variable Lifecycle
According to the official documentation, global variables are reset in the following situations:
End of a session
Use of the “Clear Variable Value” node
The “Clear Variable Value” node can either be used within the system topic “Reset Conversation” or directly within a specific topic. ※ Details about “sessions” will be covered on another occasion.
For more information about the lifecycle of global variables, refer here.
Relying too heavily on global variables can make variable management complex and increase the likelihood of bugs. Therefore, it is recommended to use arguments and return values for passing values between topics.
Adding Arguments: Receiving Values from Other Topics
To receive values from other topics, create an argument by selecting [Details] > [Inputs] in the topic settings and clicking “Create a new variable.”
This allows you to select the argument you just created in the “Calling Topic” under [Add an input].
You can then pass a value (in this example, a topic variable).
Here’s how it works when executed:
Adding Return Values: Returning Values to Other Topics
To return a value, go to [Details] > [Outputs] in the topic settings and create a new variable.
Within the topic, set the return value using the [Set a Variable] node.
This adds an “Output” option to the redirect node in the “Calling Topic,” allowing you to reference the return value.
That concludes the explanation of global variables and topic variables.
System Variables
There are too many system variables to list them all, but here are the ones you’ll likely use most often:
Activity.Text: The last message sent by the user in the current activity
LastMessage.Text: The message previously sent by the user
User.Email: The user’s email address
User.PrincipalName: The user’s UPN (User Principal Name)
※ For the difference between `Activity.Text` and `LastMessage.Text`, refer to this link.
Environment variables function similarly to those in Power Apps or Power Automate, allowing you to define different values across environments.
When you define an environment variable through a solution:
You can use them within topics. For example, this allows you to change the URL for SPO (SharePoint Online) depending on whether you’re working in a development or production environment.
※ When adding environment variables to an agent, they become mandatory objects during solution deployment. Ensure that you add them to the solution when exporting.
That concludes the explanation of the four types of variables that can be used in Copilot Studio.
コメント