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

Popular posts from this blog

[Solved] : Error: String or binary data would be truncated. Cannot execute a data definition language command on Vendor (VendLedgerReconciliationTmp)

AX 2012 - Command prompt compilation / AxBuild.exe for Parallel Compile on AOS of X++ to P-code / Parallel Compilation

AX 2012 - How to send SSRS report in email as an attachment using X++

AX 2012 - How to stop AOS when services got stuck at stopping status

AX 2012 - How to make a form field mandatory

Error: There was no endpoint listening at net.tcp://your_server_name:8201/Dynamics AX/Services…

Fetch vendor address using X++ in AX 2012

AX 2012 - How to print current date and time on SSRS Report

[Solved] : AX 2012 - No connection could be made because the target machine actively refused it 192.168.10.249:8201

[Error] - Error in unit of amount in currency KES. Must be rounded to 0.01 | The unit of 37.563.5343100000000000 KES being posted to account 32710001-- is outside the current penny rounding threshold | Posting has been canceled