Question
· Oct 27, 2016

How to track the last modified by user name

Hi,

Is there any way to track the 'last modified by' cache user name and datetime of last modification for a class or routine definition [Track Last Code Changes]?

Thanks,

Tirthankar

Discussion (10)1
Log in or sign up to continue

You can add logic in %OnAfterSave() for your object which will grab the object ID, $Username and the timestamp and tuck them away in an auditing table somewhere.  Alternatively you could add LastChangedBy and LastChangedTimestamp properties to your object and then populate them inside of %OnAddToSaveSet() (this is probably the most straightforward way to do it).

Hope that helps!

Sorry - I missed that.

Getting the "When" is easy - there is a timestamp in the header of the generated .INT code showing when the source was last compiled.  E.g:

 ;Sample.Address.1
 ;(C)InterSystems, generated for class Sample.Address. Do NOT edit. 10/27/2016 09:12:38AM
 ;;7A2F686C;Sample.Address
 ;
However the "Who" might prove to be more challenging. You might be able to accomplish this with a Method Generator that records the $Username and timestamp for access via a method or parameter?  See http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

For a class definition you can get the timestamp of last change from the TimeChanged property of the %Dictionary.ClassDefinition instance for the class.

For a routine, the TimeStamp property of its %Library.Routine instance is what you want.

But AFAIK the associated username isn't recorded automatically. You could use the server-side source control class interface to record this kind of thing, but it relies on whatever is making the change actually collaborating with that interface.

Do you use any form of source control?

Using a repository is a good idea for sure, but what about a solution that can help even if an 'intruder' had bypassed it and changed a class, e.g., on production server? Here is one which answers who changed SomeClassName.CLS; this code can be executed in "%SYS" namespace using System Management Portal/SQL:

SELECT DISTINCT TOP 1 s.UTCTimeStamp, s.OSUsername, s.Username, s.Description
FROM %SYS.Audit as s
WHERE s.Event='RoutineChange'
AND s.Description LIKE '%SomeClassName.cls%'
ORDER BY s.UTCTimeStamp desc

It's easy to adapt it for searching the same info for MAC, INT and INC routines.
Enjoy!