Quantcast
Channel: Martin Dráb – Goshoom.NET Dev Blog
Viewing all articles
Browse latest Browse all 48

Compare records in code

$
0
0

When saving a record, I had to check which fields had changed and react in a special way if only certain fields (and not any other) changed their value.

I could iterate all fields and compare their values in two table buffers (the original and the updated one), but I thought that D365FO might already have such logic. And indeed it has: in VersioningCompareRecordVersions class. (It exists in AX 2012 too and maybe even in older versions.)

The following example prepares two slightly different records, compares them and shows which fields differ:

// Prepare records to compare
PurchLine origLine;
PurchLine modifiedLine;
 
select firstonly origLine;
modifiedLine.data(origLine);
modifiedLine.PurchQty += 1;
modifiedLine.Name += " updated";
 
// Compare records
var comparer = VersioningCompareRecordVersions::newTableId(tableNum(PurchLine));
container changes = comparer.packChangedFields(VersioningChangeType::Updated, origLine, modifiedLine);
 
// Show modified fields
for (int i = 1; i <= conLen(changes); i++)
{
    container changedField = conpeek(changes, i);
 
    FieldId fieldId = conpeek(changedField, VersioningCompareRecordVersions::posRelatedFieldId());
    info(fieldId2name(tableNum(PurchLine), fieldId));
}

There is more what you can do with VersioningCompareRecordVersions, and there are other related classes as well (such as VersioningComparePurchLine), but this is a good starting point.


Viewing all articles
Browse latest Browse all 48

Trending Articles


Re: Prosím o určení autora - google nepomáhá


Nelze se přihlásit na Facebook přes PC


Prodám Flexi pass - 3 200


Markéta Reinischová: Chceme s Filipem Jankovičem dítě!


Od: Martina


Podzemlje - epizoda 62


Defender


Plynový kotel DAKON DS 22G - 2 500


Gymnastické řemínky na hrazdu zn. Reisport, vel. č. 2: 590


P: NooK Soundelirium THE 12.6


Qube SP26 ( XTA DP226 ) signal processor - 12 000


Narovnání,vylisování bankovek


Javorina Holubyho chata


Tinylab: Tlačítka


Levasan Maxx není gel na klouby, nýbrž hnus


RNS315 couvací kamera


Kde najdu GameInput Service ve win 10?


Redmi Note 11 Pro+ 5G (PISSARO)


MV3 Vermona, Klingenthal, NDR


Hradcany 30h fialova razena 11 1/2 11 3/4