2012年10月28日星期日

How to using X++ code to delete AOT nodes

1) TreeNode class
Sometimes, bad objects can not be removed from the AOT because when you click them, Axapta crush !! Look up this job:
static void DeleteDamnTables(Args _args)
{
    TreeNode edt, edt2;
    ;

    edt = TreeNode::findNode("Data Dictionary\\Tables");
    if (edt != null)
    {
        edt2 = edt.AOTfindChild("tablename");
        if (edt2 != null)
            edt2.AOTdelete();
    }
}
2) UtilIdElements solution
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.'); 
    } 
}

没有评论:

发表评论