6/28/2023
The Why
At times, certain users may need to be directed to a specific tab when they are sent a link in an email. This solution builds off of the existing tab code from Expanding Model Driven apps with code - Hiding Tabs until record is created. In this scenario, new users of the app will be sent an email that directs them directly to the Documentation tab.
The How
Create Parmenter
From the form select switch to classic.
Select Form Properties
Create the Parmenter as follows
Save and Publish the changes once completed.
Back at the form designer ensure the documentation tab is named “tab_documentation”
💡 Note: you may need to select “Show Hidden” to display the tab.
Code
We will be creating another code block that will work alongside the the code used in the with the following
var MEA = window.MEA || {};
var Form = MEA.Form || {};
(function () {
this.OnLoad = function (onLoadContext) {
var formContext = onLoadContext.getFormContext();
var extraParameters = Xrm.Utility.getGlobalContext().getQueryStringParameters();
var tabName = extraParameters["tab_name"];
if(tabName != undefined){
var defaultTabObj = formContext.ui.tabs.get(tabName);
defaultTabObj.setFocus();
}
};
}).call(Form);
Add Code into the solution
From the solution add the new javascript and name it tabcontrol-documentation
In the form add a new On Load event
Testing Link
Navigate to a record in the app and copy the URL. Add the following to the end of the URL.
&extraqs=tab_name=tab_documentation
The entire URL should now look like this.
https://ORGID.crm.dynamics.com/main.aspx?appid=APPID&pagetype=entityrecord&etn=TABLENAME&id=ROWID&extraqs=tab_name=tab_documentation
Copy and paste the URL into your browser and ensure that it goes to the correct tab.
Create Flow
With the code working we will now need to send an email with the correct link.
Within the solution create a Power Automate flow that will send a notification email to the supervisor when a new record is created.
💡 My Flow name is “Purchase Request Flow 1.1- Send Supervisor link to Request”
I am a big fan of Scope in Power Automate. It helps me keep flows looking clean and troubleshoot when a clow gets complicated.
This flow though is very simple. When a new request is made, Automate looks up the supervisors email, generates the URL, then sends it to the supervisor in an email.
Supervisor
To get the supervisors email, I did a lookup to the users table and used the supervisor_value as the ID.
💡 This could be taken down to one step, but I like to break them out for visualization purposes.
URL
Building the URL is fairly straightforward, the first three items are all hardcoded to my environment. The last one puts them all together in the proper format.
Conclusion
The next steps would be to make the email look better and format the URL so that it is friendly to the user getting the email. However, that will be a post for another day.