Celeste
Celeste

Reputation: 116

How do you delete a DirParty record in Ax2012?

I have noticed that when you delete a Worker, the Person record still exists in DirPerson, DirPersonName, DirPartyTable (and a bunch of other related tables).

I assume this is because of the complexities of the whole DirParty engin in Ax2012; probably to ensure that related tables which might contain data is not left without parent records. But why then is there a function in DirParty class that checks if a party can be deleted(DirParty:: canDeleteParty). I’ve also tried using the DirParty::autoDeleteParty method without success. Nothing gets deleted from the DirPartyTable.

Example:

static void myLittleDirPartyDeleteJob(Args _args)
{
    DirPartyTable       dirPartyTable;
    DirPerson           dirPerson;
    Common              partyRecord;
    DirParty            dirPartyClass;
    DirPersonRecId      personRecId;
    ;

    select firstOnly * from dirPerson where dirPerson.name == "BONANI VIRGINIA NENGWEKHULU";
    personRecId = DirPerson.RecId;

    //This is after the worker has been deleted on the HcmWorkerListPage form on HRM
    dirPartyTable = DirPartyTable::findRec(DirPerson::find(personRecId).RecId);

    if (dirPartyTable)
    {
        partyRecord = dirPartyTable;
        dirPartyClass = new DirParty(partyRecord);

        if (DirParty::canDeleteParty(dirPartyClass.getPartyRecId(),true))
        {
            DirParty::autoDeleteParty(dirPartyTable.RecId);
        }            
    }
}

The above code does not delete anything, nor are there any errors that hits the debugger.

I’ve tried putting it in transaction blocks (ttsbegin, ttscommit); selecting the record forupdate; I’ve even tried forcing a delete with DirPartyTable.doDelete()

When trying any of the above I get the following error:” The value that you are trying to add or subtract creates an invalid utcdatetime”

So my main question is: Is it possible to delete DirParty (and associated DirPerson; DirPersonName; etc.) tables, or will the party records forever be kept in the Dir* tables, even after deleting employees from the HRModule?

Upvotes: 1

Views: 4488

Answers (2)

Chromableed Studios
Chromableed Studios

Reputation: 455

Assuming you have DirParameters::find().AutoDeleteParty == true

Maybe try running

DirParty::canDeleteParty(this.RecId,_showInfoLog)

From a job, passing true for _showInfolog

Since the 'autoDeleteParty' method calls this before calling partyTable.delete() but passes false you are unlikely to see any feedback if it does not work

Upvotes: 0

Sebastian Widz
Sebastian Widz

Reputation: 2072

Please note that inside autoDeleteParty method there is a check if the AutoDeleteParty parameter is set before deleting, or you can use the code inside in your job.

Regards, Sebastian

Upvotes: 2

Related Questions