How to get the identity of the user who launched the report?

When you run a report in MSCRM 2011, you have two options for data sources: SQL or Fetch.

In SSRS execution logs, the user who ran the report is always a service account.

When using selection, the report execution log contains the CRM_FullName parameter, which contains the full name of the user who launched the report.

When using an SQL source, the CRM_FullName parameter is missing. How to find out who launched the report? There must be a way to find out, since Filtered views know who I am.

+7
source share
3 answers

There is really no way to find this information. When you create a report for MSCRM, you use a connector called "MSCRM Data Connector". This can be seen in the AdditionnalInfo column of the ExecutionLogs3 view of the SSRS instance. When using this connector and trying to show a report, you will receive a request for a username and password. Where things get interesting.

The report does not actually expect a username / password! In fact, he expects to get systemuserid (guid) as the username and organizationid (guid) as the password. He then searches the database MSCRM_CONFIG for the organization's database parameters. Then it enters the organizationโ€™s database and simply executes set context_info SYSTEMUSERID . Finally, filterviews call a function called "[dbo]. [Fn_FindUserGuid]", which retrieves context_info. Thus, the filtered views work correctly and are connected as a service account.

As you expected, we cannot know the user who ran the report because username and password hints are never logged anywhere in SSRS (for security reasons, maybe).

The best option I found for registration, which ran the report, is actually to create a stored procedure that will make the selection statement in the filtered views (or any tables, as it is), and then write the statement, procedure parameters and context_info () to a separate table . Then in SSRS, I call this function instead of directly viewing the filtered views.

+6
source

The answer has been edited to enable getting the full username if the sql source is used.

  • Register the UserID parameter with the default value as

    = User! Userid

  • Use the following query in your dataset

    SELECT DomainName, FullName

    FROM SystemUserBase

    WHERE (DomainName = @UserID)

  • Then use

    = Fields! FullName.Value

in your report.

In CRM, user data is stored in the SystemUserBase table, and the DomainName column is the actual domain \ username stored in User! UserID report. If you prefer to use views, use FilteredSystemUser instead of the SystemUserBase table.

For fetchxml, try the following: The operator operator = 'eq-userid' means equal to the current user.

 <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'> <entity name='team'> <attribute name='name' /> <attribute name='businessunitid' /> <attribute name='teamid' /> <order attribute='name' descending='false' /> <link-entity name='teammembership' from='teamid' to='teamid' visible='false' intersect='true'> <link-entity name='systemuser' from='systemuserid' to='systemuserid' alias='user'> <attribute name='fullname' /> <attribute name='systemuserid'/> <filter type='and'> <condition attribute='systemuserid' operator='eq-userid' /> </filter> </link-entity> </link-entity> </entity> </fetch> 

Then in your report, you can use the following code in the expression to get the username

= First (Fields! User_fullname.Value, "GetUserData")

where the dataset is called GetUserData strong>

+5
source

Will the username be enough? those. can you just use something like ="Generated by " & User!UserID ?

0
source

All Articles