Skip to main content
Solved

Extract data from Audit History

  • December 16, 2025
  • 2 replies
  • 21 views

ejmillar
Varsity III
Forum|alt.badge.img+1

Business Case:

Business would like to be advised on the changes to a POLine.PromisedDate.

Solution:

Create a SQL view to extract the previous POLine.PromisedDate and the date it was amended. Surface the SQL View with a DAC and join to POline.

Problem:

Changes to fields are stored in AuditHistory.ModifiedFields, which is a nvarchar(max) datatype, and I’m having difficulty extracting the data with SQL.

Has anyone else encountered this problem, and is there a more effective way to track date changes at a POLine item level?

Thanks,

Ewan.

Best answer by ejmillar

As soon as I posted this, I found another post which helped me:

 

Here is the full SQL, that I developed to extract the promised date from the AuditHistory and extract OrderType, OrderNbr and LineNbr.

 

SELECT
    ChangeID,
    ChangeDate,
    UserID,
    REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '') AS CleanCombinedKey,
    LEFT(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 2) AS OrderType,
    SUBSTRING(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 3, 8) AS OrderNbr,
    SUBSTRING(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 11, LEN(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''))) AS LineNbr,
    TRY_CAST(
        SUBSTRING(
            REPLACE(CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '|'),
            CHARINDEX('PromisedDate|', REPLACE(CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '|')) + LEN('PromisedDate|'),
            19
        ) AS datetime
    ) AS PromisedDateValue

FROM AuditHistory
WHERE TableName = 'POLine'
  AND CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN LIKE '%PromisedDate%';

2 replies

ejmillar
Varsity III
Forum|alt.badge.img+1
  • Author
  • Varsity III
  • Answer
  • December 16, 2025

As soon as I posted this, I found another post which helped me:

 

Here is the full SQL, that I developed to extract the promised date from the AuditHistory and extract OrderType, OrderNbr and LineNbr.

 

SELECT
    ChangeID,
    ChangeDate,
    UserID,
    REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '') AS CleanCombinedKey,
    LEFT(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 2) AS OrderType,
    SUBSTRING(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 3, 8) AS OrderNbr,
    SUBSTRING(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''), 11, LEN(REPLACE(CAST(CombinedKey AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), ''))) AS LineNbr,
    TRY_CAST(
        SUBSTRING(
            REPLACE(CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '|'),
            CHARINDEX('PromisedDate|', REPLACE(CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN, NCHAR(0), '|')) + LEN('PromisedDate|'),
            19
        ) AS datetime
    ) AS PromisedDateValue

FROM AuditHistory
WHERE TableName = 'POLine'
  AND CAST(ModifiedFields AS nvarchar(4000)) COLLATE Latin1_General_BIN LIKE '%PromisedDate%';


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • December 16, 2025

Thank you for sharing your solution with the community ​@ejmillar!