Redigera

Dela via


GetEnvironment method

Gets information about the environment that the control add-in is using. For more information, see Control Add-in Object.

For information about best practices on making control add-ins performant, see 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 that is logged into 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 function that is called when the Busy state of the client has changed.

Function Syntax

The syntax of the function is the following:

function onBusyChanged()
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 function that is called when the page containing the control add-in is being closed. Here the control add-in can perform local clean up before being unloaded.

Important

The control add-in is not allowed to invoke an AL trigger on the page via InvokeExtensibilityMethod at this point since the control add-in has already been disconnected from the page.

Function Syntax

The syntax of the function is the following:

function onClosed()

Example

This code example illustrates how you can assign members of the object return type to variables, use the Busy member to determine whether the client is busy, and use the OnClosed to determine when the control add-in is being closed.

var environment = Microsoft.Dynamics.NAV.GetEnvironment();  
  
var userName = environment.UserName;  
var companyName = environment.CompanyName;  
  
environment.OnBusyChanged = function() 
{  
    if (environment.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