Passing Legal Entity Context to an Embedded Power Apps App in Dynamics 365 Finance and Operations
With Platform Update 43 it is possible to pass the current legal entity context from Dynamics 365 Finance and Operations (D365F&O) to an embedded Power Apps app.
In this blog post I will look at an example where I display fixed assets for a given legal entity. The legal entity is passed from D365F&O when I open the app.
To capture the legal entity passed from D365F&O, I add the following code to the OnStart app event:

This code captures the “cmp” parameter passed from D365F&O and puts it into a variable named “FinOpsLegalEntity”.
I have added two data sources to the app:

The FixedAssetsV2 data source points to the Fixed Assets data entity in my instance of Dynamics 365 Finance and Operations (D365F&O) and the CachedAssets is a collection to hold the assets I fetch from D365F&O.
To fetch and cache the fixed assets in the app, I also add the following code to the OnStart event:
ClearCollect(CachedAssets,Filter(FixedAssetsV2,Company = FinOpsLegalEntity))
This code fetches all fixed assets from D365F&O where the Company field value is equal to the legal entity value that was passed from D365F&O when the app what started.
To display the fixed assets, I have fetched and cached from D365F&O, I add a gallery (Gallery1) to my app as shown below.

As you can see, the Items event contains the following code to populate the gallery:
SortByColumns(CachedAssets,"FixedAssetNumber")
This code uses the CachedAssets collection to populate the gallery sorted by the FixedAssetNumber column.
Lastly, I add a text field to display the legal entity passed from D365F&O as shown in the below screenshot.

As you can see, the field contains the FinOpsLegalEntity variable in the Text event to display the content of the variable.
I save the app and copy the app ID GUID. Now we are ready to embed the app into D365F&O.

In this example I would like to embed the app as a tile on the dashboard, so I open the personalisation dialogue and select Add a page from the dropdown menu.

Next I choose Power Apps from the list.

Lastly, I give the tile a name and paste the app ID GUID into the App ID field.

As you can see, the dashboard now contains a new tile named Asset list.
When I click on the tile, the app starts and as you can see, the legal entity context (usmf) has been passed to the app.

This was a very simple demonstration showing how easy it is to pass the legal entity context to a Power Apps app and use it to filter data.
This was originally posted here.

Like
Report
*This post is locked for comments