In Dynamics Ax, version 2009 onwards Document hash is mandatory to update the records using AIF.
When you read data, AIF returns a document hash field. This field contains a hash of all the RecId and RecVersion values
for each record that is returned. When you send the data back into AIF
to update a record, it recalculates the document hash from the database
records in the update and compares it to the document hash in the
inbound message. If the data has changed, for example, if a record was
updated or added, the calculated document hash will differ from the
document hash in the inbound document and AIF will return an error.
When you use the document hash, you only have to read and submit one field for comparison instead of reading and submitting the RecId and RecVersion values
for each record. However, if a concurrency error occurs when you use
the document hash, AIF can only report that a record was changed and not
which record changed.
While implementing some of the scenarios we may even need to perform update in 1 step this could be only possible when are able to generate <_DocumentHash> using X++. Below code describes same.I have created a test class which extends to AxdBaseRecordInfo and have created one method. In the method I am passing a recId for LedgerJournalTrans and it should return documenthash.
While implementing some of the scenarios we may even need to perform update in 1 step this could be only possible when are able to generate <_DocumentHash> using X++. Below code describes same.I have created a test class which extends to AxdBaseRecordInfo and have created one method. In the method I am passing a recId for LedgerJournalTrans and it should return documenthash.
class MyHashCode extends AxdBaseRecordInfo
{
}
public static str getHashCode(RecId _recId)
{
AxdBaseUpdate axdBaseUpdate = AxdbaseUpdate::construct();
Map dataSourceMap;
Query query = new Query(QueryStr(AxdLedgerGeneralJournal));
AxdBaseRecordInfo topAxdBaseRecordInfo;
QueryRun _queryRun;
str documentHash;
QueryBuildRange qr;
LedgerJournalTrans ledgerJournalTrans;
RecId recId;
;
recId = _recId;
select firstOnly ledgerJournalTrans
where ledgerJournalTrans.RecId == recId;
dataSourceMap = new Map(Types::Integer,Types::Integer);
axdbaseUpdate.buildDataSourceParentMap(dataSourceMap, query.dataSourceNo(1)) ;
query.dataSourceNo(1).addRange(fieldnum(LedgerJournalTrans, RecId)).value(queryValue(recId));
topAxdBaseRecordInfo = new AxdBaseRecordInfo(ledgerJournalTrans,1,dataSourceMap);
documentHash = topAxdBaseRecordInfo.getRecordHash();
return documentHash;
}
Job
Job
static void generateDocHash(Args _args)
{
;
info(MyHashCode::getHashCode(5637158049));
}
Above code has been designed to support AX 2012 changes, if you are looking how to perform same in AX 2009 then follow :
No comments:
Post a Comment