AX 2012 - How to delete user ids from AX using X++ code

Hi Folks,

Today, in this post we will share how you can delete unwanted user ids from AX 2012 using X++ code.

Code is following:

Create a job in AX 2012 and copy paste below code to delete user ids from AX using X++.

// Project Name: ABC_Adhoc_DeleteUserIDs
// Created by: Chirag Gupta
// Created date: 11-Sep-19
// Summary: This job will be used to delete user ids from AX 2012 using X++ code.

static void ABC_DeleteUserIDs(Args _args)
{
    UserInfo        userInfo;

    while select id from userInfo
        where userInfo.id  == 'ahmad.el'
            || userInfo.id == 'ayandak'
            || userInfo.id == 'cassim.a'
            || userInfo.id == 'claudine'
            || userInfo.id == 'elgin.ol'
            || userInfo.id == 'gareth.m'
            || userInfo.id == 'itumelen'
            || userInfo.id == 'jack.shi'
            || userInfo.id == 'junaids'
            || userInfo.id == 'lillianh'
            || userInfo.id == 'Mothusi'
            || userInfo.id == 'nerita.p'
            || userInfo.id == 'Verushab'
            || userInfo.id == 'vinodkr'
            || userInfo.id == 'zakierm'
    {
        info(userInfo.id);
    }

    // Note: Put all the user ids in where condition to select and delete.

    delete_from userInfo
        where userInfo.id  == 'ahmad.el'
            || userInfo.id == 'ayandak'
            || userInfo.id == 'cassim.a'
            || userInfo.id == 'claudine'
            || userInfo.id == 'elgin.ol'
            || userInfo.id == 'gareth.m'
            || userInfo.id == 'itumelen'
            || userInfo.id == 'jack.shi'
            || userInfo.id == 'junaids'
            || userInfo.id == 'lillianh'
            || userInfo.id == 'Mothusi'
            || userInfo.id == 'nerita.p'
            || userInfo.id == 'Verushab'
            || userInfo.id == 'vinodkr'
            || userInfo.id == 'zakierm';

    info("Deletion done");
}

Author:
Chirag Gupta
Microsoft Dynamics 365 AX Technical Consultant at IBM Bangalore

Date:
11-Sep-2019

Happy Learning !!

Comments