Skip to content

Commit

Permalink
Add access to countryLetterCode and preferredLanguage from tenant inf…
Browse files Browse the repository at this point in the history
…o. (#405)

## Challenge
When working with W1 base applications it is challenging to figure out
the country or preferred language.

## Change
Exposing countryLetterCode and preferredLanguage form the Organizational
Information page in Microsoft Administration Center enables better
defaulting.


![image](https://github.com/microsoft/BCApps/assets/9417259/0e2ffa1c-0d49-47b4-901f-3dfbe0a21aae)

Fixes #408

Internal work item: AB#493149
  • Loading branch information
SBalslev authored Dec 5, 2023
1 parent b6222f5 commit 68911f8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,29 @@ codeunit 433 "Azure AD Tenant"
begin
exit(AzureADTenantImpl.GetAadTenantDomainName());
end;

/// <summary>
/// Gets the current Microsoft Entra tenant registered country letter code.
/// Visit Microsoft Admin Cententer to view or edit Organizational Information.
/// If the Microsoft Graph API cannot be reached, the error is displayed.
/// </summary>
/// <returns>Country or region abbreviation for the organization in ISO 3166-2 format.</returns>
/// <error>Cannot retrieve the Microsoft Entra tenant country letter code.</error>
procedure GetCountryLetterCode(): Code[2];
begin
exit(AzureADTenantImpl.GetCountryLetterCode());
end;

/// <summary>
/// Gets the current Microsoft Entra tenant registered preferred language.
/// Visit Microsoft Admin Cententer to view or edit Organizational Information.
/// If the Microsoft Graph API cannot be reached, the error is displayed.
/// </summary>
/// <returns>The preferred language for the organization. Should follow ISO 639-1 Code; for example, en.</returns>
/// <error>Cannot retrieve the Microsoft Entra tenant preferred language.</error>
procedure GetPreferredLanguage(): Code[2];
begin
exit(AzureADTenantImpl.GetPreferredLanguage());
end;
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,49 @@ codeunit 3705 "Azure AD Tenant Impl."
InherentPermissions = X;

var
AzureADGraph: Codeunit "Azure AD Graph";
TenantInfo: DotNet TenantInfo;
NavTenantSettingsHelper: DotNet NavTenantSettingsHelper;
TenantDomainNameErr: Label 'Failed to retrieve the Microsoft Entra tenant domain name.';
CountryLetterCodeErr: Label 'Failed to retrieve the Microsoft Entra tenant country letter code.';
PreferredLanguageErr: Label 'Failed to retrieve the Microsoft Entra tenant preferred language code.';

procedure GetAadTenantId() TenantIdValue: Text
begin
NavTenantSettingsHelper.TryGetStringTenantSetting('AADTENANTID', TenantIdValue);
end;

procedure GetAadTenantDomainName(): Text;
var
AzureADGraph: Codeunit "Azure AD Graph";
TenantInfo: DotNet TenantInfo;
begin
AzureADGraph.GetTenantDetail(TenantInfo);
Initialize();
if not IsNull(TenantInfo) then
exit(TenantInfo.InitialDomain());

Error(TenantDomainNameErr);
end;

procedure GetCountryLetterCode(): Code[2];
begin
Initialize();
if not IsNull(TenantInfo) then
exit(CopyStr(TenantInfo.CountryLetterCode(), 1, 2));

Error(CountryLetterCodeErr);
end;

procedure GetPreferredLanguage(): Code[2];
begin
Initialize();
if not IsNull(TenantInfo) then
exit(CopyStr(TenantInfo.PreferredLanguage(), 1, 2));

Error(PreferredLanguageErr);
end;

local procedure Initialize()
begin
if IsNull(TenantInfo) then
AzureADGraph.GetTenantDetail(TenantInfo);
end;
}

0 comments on commit 68911f8

Please sign in to comment.