Question
· Aug 10, 2018

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

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

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:

Method OnInit() As %Status
{
    break
}

And here's the break:

break
 ^
<BREAK>zOnInit+1^Demo.Workflow.WFMetric.1
ENSDEMO 7e1>zw
 
%Ensemble("ArchiveFlags")=""
%Ensemble("ArchiveFlags","Demo.Workflow.WFMetric")=""
%Ensemble("ArchiveFlags","Demo.Workflow.WFMetric","iCfg")=0
%Ensemble("Config","%ModIndexFlag")=1
%Ensemble("ConfigName")="Demo.Workflow.WFMetric"
%Ensemble("Debug","TraceCat","My Terminal Output")=0
%Ensemble("Debug","TraceCat","My Terminal Output","user")=1
%Ensemble("Debug","TraceCat","user")=1
%Ensemble("DoTrace")=2
%Ensemble("JobKey")=10548
%Ensemble("LogSystemTrace")=0
<Private variables>

Thought about $zparent but it didn't help too:

ENSDEMO 7e1>w $system.Process.UserName($zparent)
CSP Gateway

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!

I don't have a %request.

Checked again and my suggested approach only works on production start, not host start, sorry.

I have a function which actually run "write $USERNAME" and if I run it from Studio returns the username!

$username returns current user, which for Ensemble job is correctly _Ensemble. You can try to query audit database for that info I guess.