Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Trying to find what Log Entry types there are

Posted on by Microsoft Employee

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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,113 Super User 2024 Season 2 on at
    RE: Trying to find what Log Entry types there are

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans