Translate

Saturday, 12 April 2025

Copilot to modify existing actions in Power Automate

 ๐Ÿš€ Using Copilot to Modify Actions in Power Automate

Here’s a step-by-step guide to using Copilot to modify existing actions in Power Automate, including practical examples and best practices to refine your workflows with AI assistance:

๐Ÿง‘‍๐Ÿ’ป How to Modify Actions with Copilot

1️⃣ Open Your Flow:

* Navigate to Power Automate → My Flows → Select the flow you want to edit.

2️⃣ Select the Action to Modify:

* Click the action (e.g., a condition, email, or SharePoint update).

3️⃣ Use Copilot in the Expression Field:

* In the field you want to edit (e.g., a formula, subject line, or condition), click Ask 
Copilot.
* Describe the change you need in natural language.

4️⃣ Apply the Suggestion:

* Review Copilot’s generated code (e.g., an expression or dynamic content).
* Click Insert to apply the change.

๐Ÿ“… Example 1: Modify a Date Format

* **Original Action:**

    ```
    @{utcNow()}
    ```

* **Goal:** Change the date format to "07-Apr-2025 03:30 PM".

* **Prompt Copilot:**

    * “Format the current date as dd-MMM-yyyy hh:mm tt.”

* **Copilot Generates:**

    ```
    @formatDateTime(utcNow(), 'dd-MMM-yyyy hh:mm tt')
    ```

๐Ÿงฐ Example 2: Adjust a Condition

* **Original Condition:**

    ```
    @greater(item()?['Sales'], 1000)
    ```

* **Goal:** Check if sales exceed $1,000 *and* the region is "North America".

* **Prompt Copilot:**

    * “Add a check for Region equals North America.”

* **Copilot Generates:**

    ```
    @and(greater(item()?['Sales'], 1000), equals(item()?['Region'], 'North America'))
    ```

๐Ÿ“ฆ Example 3: Add Error Handling

* **Original Action:**

    ```
    @{triggerBody()?['Department']}
    ```

* **Goal:** Replace null values with "Unassigned".

* **Prompt Copilot:**

    * “Show ‘Unassigned’ if Department is empty.”

* **Copilot Generates:**

    ```
    @coalesce(triggerBody()?['Department'], 'Unassigned')
    ```

๐Ÿ”ค Example 4: Format Text

* **Original Action:**

    ```
    @{triggerBody()?['CustomerName']}
    ```

* **Goal:** Convert the name to uppercase and add "VIP-" as a prefix for premium customers.

* **Prompt Copilot:**

    * “Prefix VIP- and make the name uppercase.”

* **Copilot Generates:**

    ```
    @concat('VIP-', toUpper(triggerBody()?['CustomerName']))
    ```

๐Ÿ“ Example 5: Update a SharePoint Field

* **Original Action:**

    ```
    Status: @{triggerBody()?['Status']}
    ```

* **Goal:** Set status to "Approved" if the amount is over $500, else "Pending".

* **Prompt Copilot:**

    * “Set status to Approved if Amount > 500, else Pending.”

* **Copilot Generates:**

    ```
    @if(greater(triggerBody()?['Amount'], 500), 'Approved', 'Pending')
    ```

Best Practices

* ๐Ÿงช   **Test Changes:** Use the Compose action to validate Copilot’s output before updating 
critical steps.
* ✍️   **Refine Prompts:** Be specific (e.g., “Convert the date to ISO format” instead of 
“Fix the date”).
* ๐Ÿ”—   **Check Connectors:** Ensure modified actions have valid permissions 
(e.g., SharePoint access).

⚙️ Advanced Modifications

* 1️⃣  **Parse JSON Responses**

    * **Original Action:**

        ```
        @{body('HTTP_Request')}
        ```

    * **Goal:** Extract the city field from a nested JSON response.

    * **Prompt Copilot:**

        * “Get the city from body\['customer']\['address'].”

    * **Copilot Generates:**

        ```
        @body('HTTP_Request')?['customer']?['address']?['city']
        ```

* 2️⃣  **Calculate Business Days**

    * **Original Action:**

        ```
        @{addDays(utcNow(), 5)}
        ```

    * **Goal:** Skip weekends when adding 5 days.

    * **Prompt Copilot:**

        * “Add 5 business days excluding weekends.”

    * **Copilot Generates:**

        ```
        @addBusinessDays(utcNow(), 5, 'Saturday, Sunday')
        ```

⚠️ Limitations

* **Complex Logic:** Copilot may not handle deeply nested if conditions or loops.
* **Syntax Errors:** Always validate parentheses and commas in generated expressions.
* **Connector-Specific Rules:** Some services (e.g., Dataverse) require manual configuration.

๐Ÿ† By leveraging Copilot to modify actions, you can quickly iterate on workflows, fix errors, and add advanced logic without memorizing syntax. Let me know if you’d like help with a specific scenario! ๐Ÿš€

No comments:

Post a Comment

Note: only a member of this blog may post a comment.