- Create a Power Automate Flow
- Write the JavaScript Script
- Add a Ribbon Button on the Main Grid
Step 1: Create a Power Automate Flow
The first step is to create a flow that will be triggered via an HTTP request. Here’s how you can set it up:
Create a Flow with HTTP Request Trigger:
- Go to Power Automate and create a new flow.
- Choose the trigger When an HTTP request is received.
Initialize an Array Variable:
- Add an action to initialize an array variable (e.g., Selected Record IDs) to store the GUIDs of the selected records.
Loop Through the Array:
- After initializing the array, use the "Apply to each" action to loop through the array of GUIDs.
- Inside the loop, you can perform actions like Update a record or any other processing needed.
Save the Flow:
- Once the flow is ready, save it and get the HTTP POST URL. This URL will be used to trigger the flow from the script.
Step 2: Write the JavaScript Code to Trigger the Flow
Next, you need to write a JavaScript script that will be called by the ribbon button. This script will send the selected records’ GUIDs to the Power Automate flow via an HTTP request. The script is divided into three functions:
onClickOfGridButton:
This function will be triggered when the ribbon button is clicked. It will retrieve the selected records' GUIDs from the grid and pass them to the triggerFlowOnMultipleRecords function.
sendRequest function to trigger the flow for multiple selected records.Step 3: Add a Ribbon Button to the Main Grid
Finally, we need to add a custom ribbon button that will trigger the JavaScript function.
Open Ribbon Workbench:
- Use Ribbon Workbench (available in XrmToolBox) to customize the ribbon.
Add a New Button:
- In Ribbon Workbench, create a new button on the main grid of the entity where you want to trigger the flow.
Set the Button Action:
- Configure the button to execute the Javascript function(i.e. onClickOfGridButton) when clicked. Then pass the PrimaryControl and SelectedControlSelectedItemIds as parameter.
Publish the Customization:
- After adding and configuring the button, save and publish the ribbon customizations.
Test the Solution:
- Once published, go to the main grid, select a few records, and click the ribbon button. The flow should be triggered, and the selected records’ GUIDs will be passed to Power Automate for processing.
Conclusion:
In this blog post, we've shown how to trigger a Power Automate flow on selected records from the main grid. We started by creating the flow in Power Automate, followed by writing the JavaScript function to trigger the flow. Finally, we added a ribbon button to the grid that executes the script, passing the selected records’ GUIDs to the flow for processing.





Comments
Post a Comment