Thursday, December 20, 2018

X++ job to delete data based on table prefix(cust/vend/kanban etc)

 In the below job we are deleting all data related to Kanban (prefix).you can use it for different prefix,just change the prefix in the code.

static void KanbanDelete(Args _args)
{
   
    int i =1;
    #AviFiles
    SysOperationProgress progress = new SysOperationProgress();
    Common common;
    #AOT
    Name name;
    NumberOf recordCount;
    TreeNode treeNode;
    SysDictTable sysDictTable;
    Connection      connection;
    Statement       statement;
    str             query;
    DataAreaId      currentDataArea;
    ;
    progress.setCaption("Loading…");
    progress.setAnimation(#AviUpdate);

    treeNode = TreeNode::findNode(#TablesPath);
    treeNode =  treeNode.AOTfirstChild();
    progress.setTotal(treeNode.AOTchildNodeCount());
    while (treeNode)
    {
        name = treeNode.AOTname();
        if(name like "kanban")
        {
            sysDictTable = SysDictTable::newTableId(treeNode.applObjectId());
            recordCount = sysDictTable.recordCount();
            if (recordCount)
            {
                connection = new Connection();
                statement = connection.createStatement();
                currentDataArea = curext();
                query = "delete from "+name;
                new SqlStatementExecutePermission(query).assert();
                statement.executeUpdate(query);
                CodeAccessPermission::revertAssert();
            }
        }
        progress.setText(strFmt("%1" ,name));
        progress.setCount(i, 1);
        i++;
        treeNode = treeNode.AOTnextSibling();
    }

}

No comments:

Post a Comment

Deploying all SSRS reports or single report in D365FSCM Using PowerShell.

  All reports can be deployed using following commands . 1. Open PowerShell run as administrator  2.Copy and paste below command and enter....