Find CRM entity name by ObjectID

From Rami Heleg blog

Everybody knows this strange error message from CRM trace logs: Error Message: SecLib::AccessCheckEx failed. Returned hr = -2147187962, ObjectID: 48355f9a-96c5-df11-90dc-00145ebd47b6, OwningUser: 6d04898c-db79-df11-83b4-00145ebd47b6 and CallingUser: 9cfc1a56-da79-df11-83b4-00145ebd47b6. 

CRM failed to perform some action on an entity with ObjectID = 48355f9a-96c5-df11-90dc-00145ebd47b6
The error does not contain the problematic entity name I prefer to know.
So I wrote the SQL script that helps me to find an entity name by ObjectID

DECLARE @objectId uniqueidentifier

SET @objectId = ’41DC59A0-96C5-DF11-90DC-00145EBD47B6′ – Set your ObjectID here

DECLARE @entityName nvarchar(255), @baseEntityName nvarchar(255), @primaryKeyColumnName nvarchar(255), @sql nvarchar(max), @isActivity bit

DECLARE cur CURSOR FOR SELECT Name, BaseTableName, IsActivity from Entity with (nolock) where IsValidForAdvancedFind = 1

OPEN cur

FETCH NEXT FROM cur INTO @entityName, @baseEntityName, @isActivity
WHILE @@FETCH_STATUS = 0
BEGIN
if(@isActivity = 1 OR @entityName = ‘ActivityPointer’)
SET @primaryKeyColumnName = ‘activityid’
else
SET @primaryKeyColumnName = @entityName + ‘id’
SET @sql = ‘IF EXISTS(SELECT ‘ + @primaryKeyColumnName + ‘ FROM ‘ + @baseEntityName + ‘ WHERE ‘ + @primaryKeyColumnName + ‘=”’ + CONVERT(nvarchar(36), @objectId) + ”’) SELECT ”’ + @entityName + ””
exec(@sql)
IF @@ROWCOUNT > 0 BREAK;
FETCH NEXT FROM cur INTO @entityName, @baseEntityName, @isActivity
END
DEALLOCATE cur

More…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: