{"title":"Use the GetEnvironment method in a control add-in","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods/devenv-getenvironment-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods/devenv-getenvironment-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Use the GetEnvironment method in a Business Central control add-in to read user, company, client platform, interaction mode, and busy-state details.","date":"2026-10-05","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Use the GetEnvironment method in a control add-in","slug":"use-the-getenvironment-method-in-a-control-add-in","at":0,"chars":3270},{"level":2,"title":"Method signature","slug":"method-signature","at":333,"chars":69},{"level":2,"title":"Return value","slug":"return-value","at":402,"chars":2133},{"level":2,"title":"Example","slug":"example","at":2535,"chars":578},{"level":2,"title":"Related information","slug":"related-information","at":3113,"chars":157}],"text":"# Use the GetEnvironment method in a control add-in\nGets 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>.\nLearn more about control add-in performance in Control add-in best practices<../devenv-control-addin-bestpractices>.\n## Method signature\n`object Microsoft.Dynamics.NAV.GetEnvironment()`\n## Return value\nReturns an object that contains the following members:\nMember|Description\nUserName|Type: String<br /><br />The name of the user who is signed in to the Dynamics 365 Business Central service.\nCompanyName|Type: String<br /><br /> The name of the company that the current user is using on the Dynamics 365 Business Central service.\nDeviceCategory|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.\nBusy|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.\nOnBusyChanged|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.\nPlatform|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.\nUserInteractionMode|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\nOnClosed|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()`\n## Example\nThis 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.\n```javascript\nvar environment = Microsoft.Dynamics.NAV.GetEnvironment();\n\nvar userName = environment.UserName;\nvar companyName = environment.CompanyName;\n\nenvironment.OnBusyChanged = function(busy)\n{\n    if (busy) {\n        // The client is now busy.\n    }\n    else {\n        // The client is not busy anymore.\n    }\n}\n\nenvironment.OnClosed = function()\n{\n    // This control is being closed.\n}\n\n```\n## Related information\nAL method reference<../methods-auto/library>\ndevenv-getimageresource-method\ndevenv-invokeextensibility-method\ndevenv-openwindow-method"}