編輯

Use the GetEnvironment method in a control add-in

Gets information about the environment that the control add-in is using. Learn more about control add-ins in Control add-in object.

Learn more about control add-in performance in Control add-in best practices.

Method signature

object Microsoft.Dynamics.NAV.GetEnvironment()

Return value

Returns an object that contains the following members:

Member Description
UserName Type: String

The name of the user who is signed in to the Dynamics 365 Business Central service.
CompanyName Type: String

The name of the company that the current user is using on the Dynamics 365 Business Central service.
DeviceCategory Type: Integer

An integer indicating the type of device that the control add-in is being rendered on. Possible values:

0 – Desktop client, either Dynamics NAV Client connected to Business Central or Business Central Web client.

1 – Business Central tablet client.

2 – Business Central phone client.
Busy Type: Boolean

A boolean indicating whether the client is currently busy. The client could, for example, be busy performing an asynchronous call to the server.
OnBusyChanged Type: Function

A callback that runs when the client's Busy state changes.

Syntax: function onBusyChanged(busy), where busy is a boolean that contains the new state.
Platform Type: Integer

An integer indicating the underlying platform that the control add-in is being rendered on. Possible values:

0 – Dynamics NAV Client connected to Business Central.

1 – Business Central Web client, Business Central tablet client, or Business Central phone client in a browser.

2 – Business Central Mobile App.

3 - Microsoft Office add-in.
UserInteractionMode Type: Integer

An integer indicating the user interaction mode that the control add-in is being rendered under. Possible values:

0 - Mouse

1 - Touch
OnClosed Type: Function

A callback that runs when the page containing the control add-in closes. The control add-in can perform local cleanup before the page unloads it.

Important

The control add-in can't invoke an AL trigger through InvokeExtensibilityMethod at this point because the control add-in is already disconnected from the page.

Syntax: function onClosed()

Example

This example assigns object members to variables, handles changes to the Busy state through OnBusyChanged, and uses OnClosed to detect when the control add-in closes.

var environment = Microsoft.Dynamics.NAV.GetEnvironment();  
  
var userName = environment.UserName;  
var companyName = environment.CompanyName;  
  
environment.OnBusyChanged = function(busy)
{
    if (busy) {
        // The client is now busy.
    }
    else {
        // The client is not busy anymore.
    }
}

environment.OnClosed = function() 
{
    // This control is being closed.
}
  

AL method reference
GetImageResource method
InvokeExtensibilityMethod method
OpenWindow method