Dynamics 365 Business Central: How to update/sync only one user from Microsoft 365

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about an interesting topic, how to update/sync only one user from Microsoft 365.
As you might know, after you add users or change user information in the Microsoft 365 Admin Center, you can quickly import the user information to Business Central. 

  1. Sign in to Business Central using an administrator account.
  2. Choose the Lightbulb that opens the Tell Me feature. icon, enter Users, and then choose the related link.
  3. Choose Update Users from Microsoft 365.

The Update Users from Microsoft 365 guide doesn’t update users that are not assigned a license, such as someone who is Global Admin and Dynamics 365 Admin. Those users will update the next time they sign in to the environment.

More details: To add users or update user information and license assignments in Business Central

This will synchronize all users, so can we sync just a certain user? As far as I know the standard can’t do it as of now. But I did some research and found that customization can be done. Let’s see more details.

PS: In fact, in addition to customization, there is a simple way. You only need to sign in to the BC environment once with the user account, and the user will be automatically added.

This time we will use codeunit 9010 “Azure AD User Management” -> procedure SynchronizeLicensedUserFromDirectory.

Synchronizes a user with the Microsoft Entra user corresponding to the authentication.

Let me test it briefly first. Assign a BC license to a new user.
reneel@CRMbc158444.OnMicrosoft.com

Test code:

Update a user from Microsoft 365

Great.

We can improve it and make an input box so that users can enter the email address that needs to be synchronized.

Test video: Youtube

Business Central short video: Update/synconly one user from Microsoft 365 (Customization)

Great, give it a try!!!😁

Test code:

pageextension 50112 UsersExt extends Users
{
    actions
    {
        addafter("Update users from Office")
        {
            action(UpdateAUserFromMicrosoft365)
            {
                Caption = 'Update a user from Microsoft 365';
                Image = Users;
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;

                trigger OnAction()
                var
                    InputUserEmailDialog: Page "Input User Email Dialog";
                begin
                    if InputUserEmailDialog.RunModal() = Action::OK then
                        InputUserEmailDialog.SynchronizesAUser();
                end;
            }
        }
    }
}
page 50103 "Input User Email Dialog"
{
    PageType = StandardDialog;
    Caption = 'Input User Email';

    layout
    {
        area(content)
        {
            field(UserEmail; UserEmail)
            {
                ApplicationArea = All;
                Caption = 'User Email';
                ExtendedDatatype = Email;
            }
        }
    }

    var
        UserEmail: Text;

    procedure SynchronizesAUser()
    var
        AADUserMgt: Codeunit "Azure AD User Management";
    begin
        AADUserMgt.SynchronizeLicensedUserFromDirectory(UserEmail);
    end;
}

PS: If the email you enter is not included in the tenant, the following runtime error will occur.

END

Hope this will help.

Thanks for your reading.

ZHU

コメント

Copied title and URL