Ensemble - Username
Hi,
Not sure if is possible, but I am trying to find the way to show in the log the username of whoever enable a specific service. The idea is that a service is normally disabled..if someone enable it, the username will be reported to the log...
I have tried with $username but it only return "_Ensemble" when running from ensemble although it works in Studio.
Thanks
Audit database contains correct username:
You can also get Username by these two ways:
But they are not as reliable as audit database.
Thanks but I am afraid that did not work... when adding that into my service code and run it... I had an error message:
ERROR <Ens>ErrException: <UNDEFINED>zOnInit+14^CUH.Serv.ODSCodeGlobalUpdate.1 *%request -- logged as '-' number - @' Do ##class(Ens.Util.Log).LogInfo($classname(),"OnInit",%request.GetCookie("Username"))'
ERROR <Ens>ErrException: <UNDEFINED>zOnInit+13^CUH.Serv.ODSCodeGlobalUpdate.1 ^CacheTemp.EnsUsername(960) -- logged as '-' number - @' Do ##class(Ens.Util.Log).LogInfo($classname(),"OnInit",^CacheTemp.EnsUsername($job))'
Username would be _Ensemble because Ensemble switches users.
Tried OnInit, available context is not enough there:
And here's the break:
Thought about $zparent but it didn't help too:
That's exactly what I am doing...using OnInit method:
{
SET tSC=$$$OK
// Add info to the log.
$$$LOGINFO("*******************************")
$$$LOGINFO("Run by:"_$Username)
$$$LOGINFO(" > "_$SYSTEM.Process.UserName())
...
Nothing works...
As I said
First one may not work at all, try safe get: $g(^CacheTemp.EnsUsername($job)).
Second one wouldn't work outside of CSP/ZEN context. Check that %request exists and is an object before calling GetCookie method.
Thank you but not sure about what you said.
I don't have a %request. It is just a Business Service doing nothing...and all I want is to get the username who enable it last time. Well, actually not last time. The service is normally off, so when is turned on, I want the username to be recorded in the log.
I have a function which actually run " write $USERNAME" and if I run it from Studio returns the username!
Checked again and my suggested approach only works on production start, not host start, sorry.
$username returns current user, which for Ensemble job is correctly _Ensemble. You can try to query audit database for that info I guess.
I haven't tested this myself, but did you try using the OnInit() callback method?
There's a bit of information here.
Maybe you're already doing this and finding $username="_Ensemble"