Passing current Company ID to Crystal Report

Does anyone know how to query from a custom-made crystal report the company ID (current company) in which the user is registered after login in EPICOR?

The menu item that we add in the E10 menu links to a single rpt which in turn points to the same ODBC regardless of the company to which the user is connected in EPICOR at any given time. The idea is to avoid prompting to the users to choose from a list of companies each time they run a report while connected to a particular company.

IF the user is only related to only one company then you could get their current userID from windows, use that to query the UserFile table and then link back to the User in the CompanyList field

Jose, thank you for your response.

Well, it could be more than one company that the user is authorized to use, so eventually he or she has to be prompted to pick one, but only for those companies the user is entitled to use. But looking at the UserFile you mentioned, now I see that there is a column CurComp that holds the company ID after the user login in EPICOR. But, if the user changes companies without login out / in from EPICOR (just by clicking on the comapany name in the general menu), then the CurComp won’t update.

Only problem is that some of our user IDs in EPICOR do not match the user ID in windows.

You can link them in user file. Link the windows and the user ID

The best way to handle this would be to create an external datasource link and external BAQ linking to a view in the target database, which should allow for filtering on current company.

If this is not possible in your version of Epicor, the way I might handle this problem would be to create an option field in a BAQ Report which is linked to a blank BAQ (depending on your version, this may need to return one record, so maybe include the company BO with one field). In the BAQ launch form, customize the option field to be hidden and populate on form load with CallContextClientData.Cur-Comp.

Then, create your ODBC datasource and report within the generated Crystal report and alter your custom query to pull the company parameter from the Epicor-provided option parameter.

Users would need to click on the BAQ report menu option, which would still allow them to schedule the report, etc. and click print preview, going through the business logic.

@Daniel
In User Account Maintenance in Epicor you can set the Domain / Windows User ID and Link it to the Epicor account

Then you should be able to pretty easily look up the current user in windows and figure out which user they are in Epicor. Now if you are using a “Shared” Computer where multiple users log in to Epicor but only a “Kiosk” type user is in Windows this approach won’t work.

@josecgomez.trigemco
There is no problem in doing the link (most users have the ID on that field.

The problem is that I need to know the Windows User ID when running the CR and match it with the field “Domain User ID”. So far, I have tried a bunch of functions / formulas but the don’t work.

Create a connection to NT Current Event Log

Use [LOCAL]

For the source computer , pick Application

Then Filter the User Type / Domain and you should have it.

I’ve only followed this topic on my phone in between vape breaks so forgive
me if this less than helpful, but if you are calling report from code you
could use this to get that data and potentially pass a parameter:

Use the System.Security.Principal.WindowsIdentity class.

Then to get the information you require:

WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

//domain/login
currentIdentity.name

It’s s link from the epicor menu (no code)

5 posts were split to a new topic: Pass Current User to External BAQ

I am just a script kiddie - but I would suggest starting with a BAQ Report - only include the Company table and you will then have the Company and UserID and anything else you want.

Then in Crystal you will have the BAQ Report XML that has your user context i.e. Name, company, Plant, etc. and then you can add ODBC tables to the Crystal report and just join the tables.

ODBC is not a preferred connection - but if you have your heart set on it - ODBC away.