Monday, July 27, 2009

How to pass the logged in user name to the store procedure or query in Crystal Reports.

Crystal Report has this lilmitation that you cannot use or pass the Crystal Special fields to the stored procedure or command object as a parameter, say if you want to retrieve the data of the current logged in user as

Select * from tUser where user_id = CurrentCEUserName

CurrentCEUserName is the crystal special field. To achieve the above thing, please follow the following steps.

1) Create a blank report, suppress all the sections except the report footer.
2) Add a formula field and place the special field CurrentCEUserName in the formula.
3) Create a subreport in the and place in the report footer.
4) Create the command with parameter UserId in the subreport.
5) From main report link the formula field created with the subreports command parameter.This way the Current CE User Name will be available in the subreport which is actually our main report.

Hope this helps,

Thanks.

2 comments: