Saturday, June 27, 2009

How to delete AOT nodes by code (UtilIdElements solution)

In my old post: How to delete AOT objects (AX/Axapta), I have used the TreeNode class. There is another useful method by using the UtilIdElements system table described in the following links:

- MS KB 913530 (CustomerSource)
- forum topic: microsoft.public.axapta.programming - Currupt records in UtilIdElement and UtilElements

Warning: Serious problems might occur if you modify the UtilIdElements table using this or another method. Modify system tables at your own risk.

The code:

static void Job1(Args _args) 
{ 
    UtilIdElements utilElement; 
    ; 

    ttsbegin; 

    select utilElement 
        where utilElement.name == 'myElementName'
        && utilElement.utilLevel == utilEntryLevel::cus // any layer 
        && utilElement.recordType == utilElementType::Table; // object type 

    if (utilelement) 
    { 
        utilElement.delete(); 

        ttscommit; 
        info('Record should be deleted now.'); 
    } 
    else 
    { 
        ttsAbort; 
        info('Could not delete record, or it was not found.'); 
    } 
}

1 comments:

Mr. Denize said...

Sweet - but oughtn't you use throw error instead of ttsabort?


View My Stats