In AX 4.0 you can click on record info->Database Log->History and there is a field called "type of change". I am trying to capture that string so that I can update a table with only updates where there have been changes to certain fields. Is there a way to do this?
heres the code:
static void SysDatabaseLogExtract_InventTableModule(Args _args)
{
//NOTE: job takes about 15-20 minutes. Delete all records from "inventTableModuleLog" first
InventTableModule inventTableModule;
PMF_InventTableModuleLog inventTableModuleLog;
SysDataBaseLog log;
container tmp;
FieldId fieldId;
List datalist;
ListEnumerator enumerator;
boolean dataFound;
int cntInsert;
;
// only sales type where log records exist
while select inventTableModule
where inventTableModule.ModuleType == ModuleInventPurchSales::Sales
join log
where log.table == inventTableModule.TableId
&& log.LogRecId == inventTableModule.RecId
{
inventTableModuleLog.clear();
inventTableModuleLog.Price_New = -999;
inventTableModuleLog.Price_Old = -999;
inventTableModuleLog.PriceUnit_New = -999;
inventTableModuleLog.PriceUnit_Old = -999;
dataFound = false;
datalist = log.getDataAslist();
enumerator = datalist.getEnumerator();
while (enumerator.moveNext())
{
tmp = enumerator.current();
fieldId = conpeek(tmp, 1);
// NOTE: run job "getFieldId" to get extended fieldIds
if(fieldId==65540) // Price
{
if(conpeek(tmp,3) != "" && log.LogType.ToString() == "Update") //Doesn't work
{
inventTableModuleLog.Price_New = conpeek(tmp,2);
inventTableModuleLog.Price_Old = conpeek(tmp,3);
dataFound = true;
}
else
{
DataFound = false;
}
if(log.LogType == "Insert")
{
inventTableModuleLog.Price_New = conpeek(tmp,2);
inventTableModuleLog.Price_Old = conpeek(tmp,3);
dataFound = true;
}
}
if(fieldId==65541) // PriceUnit
{
if(conpeek(tmp,3) != "" && log.LogType == "Update")
{
inventTableModuleLog.PriceUnit_New = conpeek(tmp,2);
inventTableModuleLog.PriceUnit_Old = conpeek(tmp,3);
dataFound = true;
}
else
{
DataFound = false;
}
if(log.LogType=="Insert")
{
inventTableModuleLog.PriceUnit_New = conpeek(tmp,2);
inventTableModuleLog.PriceUnit_Old = conpeek(tmp,3);
dataFound = true;
}
}
if(fieldId==65560) // OverDeliveryPct
{
if(conpeek(tmp,3) != "" && log.LogType == "Update")
{
inventTableModuleLog.OverDeliveryPct_New = conpeek(tmp,2);
inventTableModuleLog.OverDeliveryPct_Old = conpeek(tmp,3);
dataFound = true;
}
else
{
dataFound=false;
}
if(log.LogType == "Insert")
{
inventTableModuleLog.OverDeliveryPct_New = conpeek(tmp,2);
inventTableModuleLog.OverDeliveryPct_Old = conpeek(tmp,3);
dataFound = true;
}
}
if(fieldId==65561) // UnderDeliveryPct
{
if(conpeek(tmp,3) != "" && log.LogType == "Update")
{
inventTableModuleLog.UnderDeliveryPct_New = conpeek(tmp,2);
inventTableModuleLog.UnderDeliveryPct_Old = conpeek(tmp,3);
dataFound = true;
}
else
{
dataFound=false;
}
if(log.LogType == "Insert")
{
inventTableModuleLog.UnderDeliveryPct_New = conpeek(tmp,2);
inventTableModuleLog.UnderDeliveryPct_Old = conpeek(tmp,3);
dataFound = true;
}
}
}
if(dataFound)
{
inventTableModuleLog.Description = log.Description;
inventTableModuleLog.LogType = log.LogType;
inventTableModuleLog.table = log.table;
inventTableModuleLog.LogRecId = log.LogRecId;
inventTableModuleLog.LogCreatedDate = log.createdDate;
inventTableModuleLog.LogCreatedTime = log.createdTime;
inventTableModuleLog.LogCreatedBy = log.createdBy;
inventTableModuleLog.ItemId = substr(log.Description,1,strfind(log.Description,',',1,99)-1);
inventTableModuleLog.insert();
cntInsert++;
}
}
info(strfmt("%1 records inserted",cntInsert));
}
*This post is locked for comments
Hi,
You can setup the database log to log only changes to some fields. You have to select the fields from the table to log the update instead of the table node itself when setting up the database log.
However if you are only concerned about the sales type records, it will log too much.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,113 Super User 2024 Season 2
Martin Dráb 229,918 Most Valuable Professional
nmaenpaa 101,156