In my previous post I explained about creating journals using entities through recurring data jobs. In this post I am going to share about how generation of auto numbers happens during import through data management and issue I encountered while importing multiple journal lines in same journal.
Let’s say we want to import 100 lines into the same journal. So I created a data project with my entity LedgerJournalEntity . LedgerJournalEntity does set based operations.I modify the source-to-staging format, marking JournalNum auto generated.
When I executed import I saw total 100 different journal numbers were allocated in staging table instead of single journal numbers for all lines, which is definitely not I want. This features works grate for some of the entities I used . I encountered issue only for this particular entity.
When I debugged coded I found that auto number generation is done through methods autoGenerateNos and generateAutoNumbers of class DMFGenerateSSISPackage. Separate piece of code is written to handle composite and normal entities. autoGenerateNos method gets the count of record from staging using direct SQL query which is further used in generateAutoNumbers method.
In generateAutoNumbers method direct SQL function FN_FMT_NUMBERSEQUENCE is called through method createFnFmtNumberSequence_TSQL which generates number sequences and updates those in staging table. Updates to NnumberSequencetable are also done in the same method, however at this point no number sequences are generated inside D365 .
There’s the “Free” number consideration for continuous number sequence as well .So if you have free 50 numbers those would be assigned to lines first and then 50 are generated from continuous number sequences.
The fix I did is fairly simple and worked for me , so that I don’t have to go deep in these standard methods and changed anything over there. I turned of auto number generation in my data project and overridden postGetStagingData method to generate Journal number sequence and update that number on my staging records with the following code ,which I want to be imported as a part of single journal .
LedgerJournalEntityBaseTmp journalBatchNumberMap = LedgerJournalEntityBase::generateJournalNumbers(_dmfDefinitionGroupExecution, staging); update_recordset staging setting JournalBatchNumber = journalBatchNumberMap.NewJournalBatchNumber where staging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup && staging.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId && staging.TransferStatus == DMFTransferStatus::NotStarted;
If you encounter any issue with auto number generation , you know the place where to look for. If you have any questions feel free to comment.