With OData actions we are able to invoke operations in Data Management. This way we can start import and export jobs or query various data elements.
This is useful when we want an external application or user to create files on demand.
In this example I am using the OData actions to export data to a spreadsheet and subsequently open the spreadsheet from a Power Apps app.
In Data Management, we do not need to anything special to make this work. In principle, any data project can be called using an OData action.
The below screenshot shows the definition of the “Customer FTI” data job I will be using in this example.
The Power Apps App
To make this example meaningful, I have created a simple Power Apps app that displays the Data Management data projects in a gallery as shown below.
Not pretty but it does the job…
In the OnSelect action on the arrow in the gallery, I have added a single line of code:
Launch(ExportDataPackage.Run(Gallery1.Selected.Description).filepath)
The code calls a Power Automate flow called “ExportDataPackage”. This flow returns the full path to the file generated by the selected data job.
The selected data job ID (Description field) is passed to the flow as a variable.
The Power Automate Flow
Obviously, the interesting part of this example is the Power Automate flow so let us have a look at it.
The flow is an instant type of flow, and we start by capturing the data job ID passed from the app and put it into a variable name DefinitionGroupId.
Next, we generate a fresh GUID value. This value is used later on to give our job execution an identification and store the data package.
In the above action, we call the OData action to export a data package from Data Management. The data project ID we received from the app is used to identify the data job to call and the ExecutionID GUID we generated earlier identifies the actual job we are executing.
This step, assuming it is successful, generates a data package (ZIP archive) in the dedicated Dynamics 365 Finance and Operations (D365F&O) storage area.
To retrieve the data package, we need to get the URL that points to where it is placed. We can use the GetExportedPackageUrl OData action to get the URL. In this example, I have placed the action inside a Do-until condition since there may be a slight delay when generating the package.
Subsequently, we can use an HTTP action to retrieve the actual data content using the URL we got in the previous step.
Now that we have the package content, we need to retrieve the files from the archive and place them in a usable folder. In this case we are using the OneDrive connector to perform the necessary file manipulation.
First, we use the body content from the HTTP call to generate the archive on OneDrive.
Then, we extract the files in the archive into a new folder named with the ExecutionID.
Lastly, since we do not always know the name on the spreadsheet file generated by the data job, we find the first file in the folder with the “.XLSX” extension.
When the file has been found, we continue to use the OneDrive connector to generate a link to the file.
As you may remember from the app section above, we used the Launch command to open the file we have generated. This command takes a URL as a parameter so we can pass the link we generated in the above step to the command, and it will open the spreadsheet in a browser tab.
In the final step, we pass the link to the spreadsheet file back to the app.
Testing
Now everything has been configured, it is time to test it.
When I click on the arrow on the row containing the “Customer FTI” data job, the flow is invoked and generates the data package on OneDrive as shown below.
The flow has also extracted the files from the archive into a folder with same name.
In this case, the data package contains a spreadsheet file named “Customer free text invoice.xlsx”.
The above screenshot shows how the Launch command has opened the spreadsheet in a tab in the browser.
You must log in to post a comment.