In certain scenarios, it may be important to know what client that the user is working in. Perhaps you have an action that doesn’t work in the Web Client, or maybe you have some code that interacts with a device camera that only works in the Device Client. Or maybe you want to send a link to your users that allows them to open a record, and we want to make sure the link is for the correct client?
First, I want to be clear that what I am describing here is based on the Dynamics NAV 2017 platform. Yes, this means the Dynamics 365 for Financials platform falls under this umbrella as well. Perhaps bits and pieces are supported on older platforms, but my intention is to never look backwards and keep this train moving forward!
Now to it…
There are some system variables that we need to get familiar with:
- an option variable that contains the various client types:
- Returns the client type that is currently executing the code.
- Returns the default client type, as defined in the Dynamics NAV Server configuration. For more information click here.
Example 1: Show an action only in the Windows Client.
- In the Development Environment, design the page that contains the action.
- Make sure that the action does something. If it does not do anything, then it will always be hidden. For testing purposes you can add the following code to the onAction trigger for the action:
MESSAGE('A message for testing');
- Add a global Boolean variable named ‘showMyAction’:
- Assign the global variable to the Visible property of the action that you wish to conditional show/hide (you can show this property as a column in the Action Designer now!!):
- Add the following code to the onOpenPage trigger:
showMyAction := CURRENTCLIENTTYPE = CLIENTTYPE::Windows;
- Close, save and compile your page.
- If you run the page in the Web Client for example, you will not see the action on the ribbon of the page. Running the page from the Windows Client will show the action.
Example 2: Create a url that takes a user to the first customer record.
- In the Development Environment, create a new codeunit.
- In the onRun trigger, create the following local variables:
- In the onRun trigger, add the following code:
url := GETURL(DEFAULTCLIENTTYPE,COMPANYNAME,OBJECTTYPE::Page,PAGE::"Customer Card",Customer);
- Close, save and compile the codeunit.
- From the Development Environment run the codeunit. A message should appear on screen with the url that was generated. In the example below, my default client was set to be the Web Client.
Hopefully you get a sense now of how you can condition your code based on the different Dynamics NAV client types.
That’s all for today!