Can see the UserName ... but can't access it

I’ve added the following routine within my customization.

 private void UD04_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
	switch (args.Column.ColumnName)
	{
		case "Key1":

This works very well and I can gain control when the value of column Key1 changes. However, when this happens I’m wanting to record the UserName value of the user currently logged into the system. What is frustrating is when putting a break point in the code after this case statement, I can see the UserName value in these object path’s:

UD04Form.Session.UserName;
this.oTrans.CoreSession.UserName;

However, when attempting to use these statements, they don’t compile. Testing the code produces this error message:

  'object' does not contain a definition for 'UserName' and no extension method 'UserName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

It’s obviously there … but not usable for me to access the value I see in the immediate window. What am I missing?

Just so I’m clear, this is how I’m trying record the UserName value:

   args.Row["ShortChar01"] = UD04Form.Session.UserName;

This does not compile.

UD04Form.Session.UserID

Make sure you add an Assembly Reference to the file Ice.Core.Session.dll

((Ice.Core.Session)(this.oTrans.Session)).UserName

If this is what you mean by adding an Assembly Reference to the Ice.Core.Session.dll, I’ve added this statement:

using Ice.Core.Session;

Before adding that, my code compiled with no errors. After adding that Using statement and only adding that statement, the code will not compile. This error is produced:

Error: CS0234 - line 19 (19) - The type or namespace name ‘Core’ does not exist in the namespace ‘Ice’ (are you missing an assembly reference?)

** Compile Failed. **

… which I find hard to believe since I do see the Ice.Core.Session.dll in the Epicor application directory. Still pretty confused.

No you go to the Script Editor. Tools -> Assembly Reference Manager

image

Ok. I did that and here’s my new statement:

args.Row[“ShortChar01”] = ((Ice.Core.Session)(this.oTrans.Session)).UserName;

That actually compiled correctly. Let me test it and I’ll get right back with you.

Thanks,

That may be the User’s Name. If you want the Username aka UserID then change it to UserID

Hey!!! You made my day! It works!!

Thank you very much!

Yeah, I could see all of these UserName, UserID, etc … but could grab them. Now I can, Thanks again.

Where would this type of documentation be for this kind of Epicor C# coding? I know the natvie controls work differently than the custom controls and I’ve not found much documentation on these issues.

Just forums, communities and understanding .NET. I think the Customization Tools Guide and the Extended Education classes do show in some cases where they reference a dll, not sure if they have an example how to get the UserID however.

Also note, not all UI’s need this assembly… I have had instances where oTrans.Session.UserID worked just fine because the UI itself referenced the assembly. Case by case basis.

On newer versions I thought you could simply use:

oTrans.CoreSession.UserName:

Am I wrong?

1 Like

That did seem to work, but is with the Ice.Core.Session.dll included. I don’t remember if I tried that one or not. I know I did try:

  this.oTrans.CoreSession.UserID

and it didn’t work. We should be using the most recent version of Epicor.

@Jason_Woods you are correct.

The difference btw oTrans.Session and oTrans.CoreSession is CoreSession will return an Ice.Core.Session object so you don’t have to cast it where as oTrans.Session just returns an object. Both roads lead to Session object, but one just requires an extra step.

public Ice.Core.Session CoreSession
{
	get { return (Ice.Core.Session)this.Session; }
}