Monday, May 2, 2011

CDC Software Pivotal CRM 6.0: View table fields audit log SQL query.

If a field marked as "Monitor on Log" then any its changes will be save in Pivotal history table.

This SQL script helps Pivotal developers to view a field change log details:

DECLARE
 @Table_Name nvarchar(28),
 @Table_Id binary(8),
 @Record_Id binary(8)

--Set input parameters
SET @Table_Name = 'Support_Incident'
SET @Record_Id = 0x8000000000000088

--Get table ID from BM database
SELECT @Table_Id = Tables_Id FROM PivotalBM.dbo.Tables WHERE Table_Name = @Table_Name

--Select audit entries for the required record from ED database
SELECT
    Journal_History.Field_Label,
    Journal_History.New_Value,
    Journal_History.Time_Stamp,
    Employee.Full_Name AS [Employee_Name]
FROM PivotalED.dbo.Journal_Items
INNER JOIN Journal_Pages ON Journal_Pages.Journal_Pages_Id = Journal_Items.Journal_Pages_Id
INNER JOIN Journal_History ON Journal_History.Journal_Pages_Id = Journal_Pages.Journal_Pages_Id
INNER JOIN Employee ON Journal_History.Rn_Create_User=Employee.Rn_Employee_User_Id
WHERE Journal_Items.Reference_Table = @Table_Id AND Journal_Items.Reference_Record = @Record_Id
ORDER BY Journal_History.Time_Stamp DESC

CRM it is no joke!

No comments:

Post a Comment