# 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<../devenv-control-addin-object>.
Learn more about control add-in performance in Control add-in best practices<../devenv-control-addin-bestpractices>.
## Method signature
`object Microsoft.Dynamics.NAV.GetEnvironment()`
## Return value
Returns an object that contains the following members:
Member|Description
UserName|Type: String<br /><br />The name of the user who is signed in to the Dynamics 365 Business Central service.
CompanyName|Type: String<br /><br /> The name of the company that the current user is using on the Dynamics 365 Business Central service.
DeviceCategory|Type: Integer<br /><br /> An integer indicating the type of device that the control add-in is being rendered on. Possible values:<br /><br /> 0 - Desktop client, either Dynamics NAV Client connected to Business Central or Business Central Web client.<br /><br /> 1 - Business Central tablet client.<br /><br /> 2 - Business Central phone client.
Busy|Type: Boolean<br /><br /> 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<br /><br />A callback that runs when the client's Busy state changes.<br /><br />Syntax: `function onBusyChanged(busy)`, where busy is a boolean that contains the new state.
Platform|Type: Integer<br /><br /> An integer indicating the underlying platform that the control add-in is being rendered on. Possible values:<br /><br /> 0 - Dynamics NAV Client connected to Business Central.<br /><br /> 1 - Business Central Web client, Business Central tablet client, or Business Central phone client in a browser.<br /><br /> 2 - Business Central Mobile App.<br /><br /> 3 - Microsoft Office add-in.
UserInteractionMode|Type: Integer <br /><br />An integer indicating the user interaction mode that the control add-in is being rendered under. Possible values:<br /><br /> 0 - Mouse <br /><br /> 1 - Touch
OnClosed|Type: Function<br /><br />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.<br /><br />Important<br /><br />The control add-in can't invoke an AL trigger through devenv-invokeextensibility-method at this point because the control add-in is already disconnected from the page.<br /><br />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.
```javascript
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.
}

```
## Related information
AL method reference<../methods-auto/library>
devenv-getimageresource-method
devenv-invokeextensibility-method
devenv-openwindow-method

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods/devenv-getenvironment-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods/devenv-getenvironment-method/
