web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Audit Triggers on HRORI012

(0) ShareShare
ReportReport
Posted on by

Hello,

Terry Healy provided my team with a script for having an audit table created when changes are made to specific tables. My team is looking to add a table HRORI012.

Here is an example of the triggers on UPR00100 my question how do I create it on this new table?

--begin---

create trigger [trackEmployeeMasterChanges]
on UPR00100
for update
as
  if update(EMPLCLAS)
    begin
      insert trackPayrollChanges
      select system_user,
             'UPR00100',
             'EMPLCLAS',
             getdate(),
             cast(a.EMPLCLAS as char(50)),
             cast(b.EMPLCLAS as char(50)),
             a.EMPLOYID,
             'Employee Class changed for Employee: ' + a.EMPLOYID
      from   deleted a
             inner join inserted b
               on a.EMPLOYID = b.EMPLOYID
    end
    
  if update(INACTIVE)
    begin
      insert trackPayrollChanges
      select system_user,
             'UPR00100',
             'INACTIVE',
             getdate(),
             cast(a.INACTIVE as char(50)),
             cast(b.INACTIVE as char(50)),
             a.EMPLOYID,
             'Inactive changed for Employee: ' + a.EMPLOYID
      from   deleted a
             inner join inserted b
               on a.EMPLOYID = b.EMPLOYID
    end
    
  if update(LASTNAME)
    begin
      insert trackPayrollChanges
      select system_user,
             'UPR00100',
             'LASTNAME',
             getdate(),
             cast(a.LASTNAME as char(50)),
             cast(b.LASTNAME as char(50)),
             a.EMPLOYID,
             'Last Name changed for Employee: ' + a.EMPLOYID
      from   deleted a
             inner join inserted b
               on a.EMPLOYID = b.EMPLOYID
    end
    
  if update(FRSTNAME)
    begin
      insert trackPayrollChanges
      select system_user,
             'UPR00100',
             'FRSTNAME',
             getdate(),
             cast(a.FRSTNAME as char(50)),
             cast(b.FRSTNAME as char(50)),
             a.EMPLOYID,
             'First Name changed for Employee: ' + a.EMPLOYID
      from   deleted a
             inner join inserted b
               on a.EMPLOYID = b.EMPLOYID
    end
    
  if update(MIDLNAME)
    begin
      insert trackPayrollChanges
      select system_user,
             'UPR00100',
             'MIDLNAME',
             getdate(),
             cast(a.MIDLNAME as char(50)),
             cast(b.MIDLNAME as char(50)),
             a.EMPLOYID,
             'Middle Name changed for Employee: ' + a.EMPLOYID
      from   deleted a
             inner join inserted b
               on a.EMPLOYID = b.EMPLOYID
    end

\........there is more, but you get the idea......../

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Tim Foster Profile Picture
    8,515 on at

    You really should ask Terry for this.

    This should work:

    CREATE TABLE trackPayrollChanges (

        USERID CHAR(50),

        TABLENME CHAR(30),

        CHNGFELD CHAR(30),

        CHGDDATE DATETIME,

        OLDDATA  CHAR(255),

        NEWDATA CHAR(255),

        EMPLOYID CHAR(15),

        MESSAGE  CHAR(255)

    )

    GO

    GRANT SELECT ON trackPayrollChanges TO DYNGRP

    GO

    Remember a trigger that fails will interrupt GP (never good).

    Remember to test before applying to a production environment.

    Tim

    P.S. I make no guarantees for this code.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Dan Liebl Profile Picture

Dan Liebl 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans