Assisted Setup and Permissions.
But first lets look at the Extension Management Codeunit.
I want to store the appId in my Extension. This appId is used in several tables in my tenant. This appId must always be the same for this solution even if the solution is updated. In my last post you can see that I am also setting my appId parameter in the Git repository. There are few easy ways to get your appId. NAV has the function CREATEGUID. Powershell has the function New-Guid. But perhaps the easiest way is to use this online Guid generator.
In OnNavAppUpgradePerDatabase – executed once when the Extension is installed, I want to assign my Extension Setup permission set to the user installing. This is required to be able to run the Assisted Setup after installation.
In OnNavAppUpgradePerCompany – executed once in every company when the Extension is installed, I want to restore data for some of the Extension tables and delete rest of the archive data. Even if I am just using tables as a temporary tables I still need to define what to do with the non-existing-archived data. In here I also want to remove the persistent Assisted Setup record in every company.
So, why would I like to remove the Assisted Setup record? Not because I like to make the user execute the setup every time the Extension is updated. The Extension has its own Setup table. In that Setup table I store the setup information belonging to this Extension and the Setup data is restored from archive during the installation as you can see above.
In the current release the Assisted Setup record is a database record. I know that Microsoft intends to change this and use the same discovery pattern that is used in Service Connections. When that happens the Assisted Setup record will be temporary only. So, by designing my Extension in this way I make sure that I will still support Assisted Setup after this change.
In NAV 2016 we had the Mini Role Center, page 9022. Today this Role Center has been updated to fit Dynamics 365 for Financials.
From here the user can access the Extension installation we covered in the last post, and we can also access the Assisted Setup & Tasks.
I add my Assisted Setup by subscribing to the OnOpenPage Event in the above page.
Looking at the Assisted Setup record we can see that is has a media field for an Icon. NAV setup data includes icon for the standard Assisted Setup items – so must we.
I decided to ship my icons with the code. Each icon has a dedicated Codeunit.
To fit an icon into a Codeunit we need to convert the binary data to base64 data. This we can do with the following code.
This allows me to create a Codeunit like this.
And then code like this to import the icon into my help resources.
Now, back to the Assisted Setup. I start the setup for my Extension.
This sums up what needs to be done. The basic setup, the one done with Set Defaults, is to assign permissions to all users based on their current permissions to the tables we build our extension around.
The G/L Source Name lookup table is read from a FlowField in G/L Entries. We can therefore expect that everyone that has read access to G/L Entries must also have read access to the lookup table. The data in the lookup table is updated when ever any of the four master tables is updated. Hence, everyone that has access to modify any of the master tables must have access to modify the lookup table.
The Set Defaults function assigns the Extension permission sets to users and user groups based on the current permissions and that should be enough in most cases. If the user likes the advanced way that possibility is available.
When the user presses Finish the wizard data and the assigned permission sets are applied to the tenant database.
When I created the Setup Wizard page I started with a copy of the Email Setup Wizard, page 1805.
The model I have created to assign permission sets to users and user groups with a Wizard can easily be modified to fit any Extension. Remember that all this code will soon be available on my GitHub account.