Cannot delete a record in TaxDocumentTransitRelation (TaxDocumentTransitRelation) in AX



While making the Vendor Invoice I was struck with the below issue. Below is the clear explanation for you all.




Error Message: Cannot delete a record in TaxDocumentTransitRelation (TaxDocumentTransitRelation). Deadlock, where one or more users have simultaneyously locked whole table or part of it.



Replace the below code from existing one.


public void deleteByTransitDocumentType(TransitDocumentType_IN _documentType)
{
    TransitDocumentTransactionRelationMap_IN   relationMap;
    Common                                     transitDocTable;
    if (!_documentType)
    {
        return;
    }
    relationMap = this.getTransactionRelationTable(_documentType.RefTableId);
    transitDocTable = new DictTable(_documentType.RefTableId).makeRecord();
    ttsBegin;
    //delete_from relationMap
   while select relationMap
        where relationMap.TransitDocumentType == _documentType.RecId
        notExists join transitDocTable
            where relationMap.TransitDocumentRecId == transitDocTable.RecId
    {
        relationmap.selectForUpdate (true);
        relationMap.delete();

    }
    ttsCommit;
}

1 comment:

  1. hi can you please update on which class where exactly we need to place this method

    ReplyDelete