๐ Expressions in Power Automate
Here's a breakdown of Expressions in Power Automate: their purpose, common functions, and examples:
❓ What Are Expressions?
- Expressions are formulas or functions used in Power Automate to ๐ ️ manipulate data, perform calculations, or add logic to your workflows.
- They allow you to dynamically transform data from triggers or actions without writing code.
- Example: ✂️ Extracting a substring from text, ⏰ converting time zones, or ๐ calculating a date.
๐ Key Concepts
- Syntax:
- Expressions start with
@and use functions likeformatDateTime(),concat(), oraddDays(). - Example:
@formatDateTime(triggerBody()?['Date'], 'yyyy-MM-dd')
- Expressions start with
- Dynamic Content vs. Expressions:
- Dynamic Content: ๐ฆ Predefined data from previous steps (e.g., email subject).
- Expressions: ⚙️ Custom logic to modify that data (e.g., formatting the subject into lowercase).
๐งฐ Common Expression Categories & Examples
- 1. String Manipulation
concat(): ๐ Combine strings.- Example:
@concat('Hello ', triggerBody()?['SenderName'], '! Your ID: ', outputs('GenerateID'))
- Example:
substring(): ✂️ Extract part of a string.- Example:
@substring(triggerBody()?['EmailSubject'], 0, 10) // First 10 characters
- Example:
toLower()/toUpper(): ๐ก Change case.- Example:
@toLower(triggerBody()?['CustomerName'])
- Example:
- 2. Date/Time Functions
utcNow(): ⏰ Get current UTC time.- Example:
@utcNow()
- Example:
addDays()/addHours(): ๐ Adjust dates.- Example:
@addDays(utcNow(), 7) // Adds 7 days to current time
- Example:
formatDateTime(): ๐ Format a date.- Example:
@formatDateTime(triggerBody()?['DueDate'], 'dd-MM-yyyy')
- Example:
- 3. Math Functions
add()/mul(): ➕ Basic arithmetic.- Example:
@add(triggerBody()?['Quantity'], 10)
- Example:
rand(): ๐ฒ Generate a random number.- Example:
@rand(1, 100) // Random number between 1-100
- Example:
- 4. Logical Functions
if(): ๐ค Conditional logic.- Example:
@if(triggerBody()?['Priority'] = 'High', 'Escalate', 'Normal')
- Example:
equals()/greater(): ⚖️ Comparisons.- Example:
@greater(triggerBody()?['Sales'], 1000)
- Example:
- 5. Data Conversion
int()/float(): ๐ข Convert to numbers.- Example:
@int(triggerBody()?['Age'])
- Example:
string(): ๐ค Convert to text.- Example:
@string(triggerBody()?['Total'])
- Example:
๐ก Example Flow Using Expressions
- Scenario: Send a reminder email 3 days before a project deadline (stored in SharePoint).
- Trigger:
- ๐
Recurrence(scheduled daily).
- ๐
- Get Project Data:
- Use
SharePoint – Get Itemsto fetch projects with deadlines.
- Use
- Apply to Each Project:
Calculate Reminder Date:@addDays(item()?['Deadline'], -3)Check if Today Matches Reminder Date:@equals(formatDateTime(utcNow(), 'yyyy-MM-dd'), formatDateTime(item()?['ReminderDate'], 'yyyy-MM-dd'))Send Email(if condition is true):Body: @concat('Reminder: Project ', item()?['Title'], ' is due on ',formatDateTime(item()?['Deadline'], 'dd MMM yyyy'))
๐ ️ How to Use Expressions in Power Automate
- In any action field, click
Add dynamic content>Expression. - Type the formula (e.g.,
substring(triggerBody()?['text'], 0, 20)). - Use the
Expression Reference(e.g.,length(),replace(),coalesce()).
๐ Benefits of Expressions
- ๐ Dynamic Data Handling: Transform data on the fly (e.g., format messy input).
- ๐ง Complex Logic: Build conditions, loops, or calculations.
- ✅ Error Reduction: Validate data before processing (e.g., check if a field is empty).
✨ Best Practices
- ๐งช Test expressions in small steps using the
Composeaction. - ๐ Use comments in complex expressions (e.g.,
/* This checks the due date */). - ๐ Combine expressions with variables for reusability.
By mastering expressions, you can create more powerful, flexible, and intelligent workflows in Power Automate! ๐
No comments:
Post a Comment
Note: only a member of this blog may post a comment.