After lots of digging i came to this solution:
- Open the organization database.
- Find "SavedQuery" view and alter it.
- Find this: "[T1].[ReturnedTypeCode]" and replace it with this:
CASE WHEN (T1.SavedQueryId = N'A2CC2D8E-9768-DD11-B1B0-00155D869F00') THEN 1039 ELSE [T1].[ReturnedTypeCode] END ReturnedTypeCode
- Execute and then recycle the CRM application pool in IIS.
But Why and How!?
Base on the error:
Inner Exception: Microsoft.Crm.CrmArgumentException: The object type code 1026 does not map to a specific label type code
at Microsoft.Crm.Metadata.LabelTypeCodeHelper.GetLabelTypeCodeFromObjectTypeCode(Int32 objectTypeCode)
...
I decompiled the CRM assembly and found the method which the error occurs:
So base on this method if "objecttypecode" 1026 come through then definitely the exception will be thrown, but why this typecode come to this method which they didn't expect?!, don't know and i think its a bug.
So after this, i ran Sql profile and found that this "objecttypecode" comes from Selecting the "SavedQuery" view and only happens on "Quick Find Product Price Levels" view with id "A2CC2D8E-9768-DD11-B1B0-00155D869F00" of "ProductPriceLevel" entity:
exec sp_executesql N'select
"savedquery0".FetchXml as "fetchxml"
, "savedquery0".StateCode as "statecode"
, "savedquery0".CreatedBy as "createdby"
, "savedquery0".ColumnSetXml as "columnsetxml"
, coalesce("LL0".Label,"LL1".Label, "savedquery0".Name ) as "name"
, "savedquery0".QueryType as "querytype"
, "savedquery0".AdvancedGroupBy as "advancedgroupby"
, "savedquery0".ModifiedBy as "modifiedby"
, "savedquery0".ReturnedTypeCode as "returnedtypecode"
, "savedquery0".CreatedOn as "createdon"
, "savedquery0".LayoutXml as "layoutxml"
, coalesce("LL2".Label,"LL3".Label, "savedquery0".Description ) as "description"
, "savedquery0".ModifiedOnBehalfBy as "modifiedonbehalfby"
, "savedquery0".ConditionalFormatting as "conditionalformatting"
, "savedquery0".StatusCode as "statuscode"
, "savedquery0".CreatedOnBehalfBy as "createdonbehalfby"
, "savedquery0".ModifiedOn as "modifiedon"
, convert(bigint, "savedquery0".VersionNumber) as "versionnumber"
, "savedquery0".QueryAPI as "queryapi"
, "savedquery0".ComponentState as "componentstate"
, "savedquery0".SolutionId as "solutionid"
, "savedquery0".SavedQueryId as "savedqueryid"
, "savedquery0".OrganizationId as "organizationid"
, "savedquery0".CreatedByName as "createdbyname"
, "savedquery0".CreatedByYomiName as "createdbyyominame"
, "savedquery0".ModifiedByName as "modifiedbyname"
, "savedquery0".ModifiedByYomiName as "modifiedbyyominame"
, "savedquery0".ModifiedOnBehalfByYomiName as "modifiedonbehalfbyyominame"
, "savedquery0".ModifiedOnBehalfByName as "modifiedonbehalfbyname"
, "savedquery0".CreatedOnBehalfByYomiName as "createdonbehalfbyyominame"
, "savedquery0".CreatedOnBehalfByName as "createdonbehalfbyname"
from
SavedQuery as "savedquery0"
left outer join LocalizedLabelView as "LL0" on ("LL0".ObjectId = "savedquery0".SavedQueryId and "LL0".LanguageId = @LanguageId0 and "LL0".ObjectColumnName = @ObjectColumnName0 )
left outer join LocalizedLabelView as "LL1" on ("LL1".ObjectId = "savedquery0".SavedQueryId and "LL1".LanguageId = @LanguageId1 and "LL1".ObjectColumnName = @ObjectColumnName1 )
left outer join LocalizedLabelView as "LL2" on ("LL2".ObjectId = "savedquery0".SavedQueryId and "LL2".LanguageId = @LanguageId2 and "LL2".ObjectColumnName = @ObjectColumnName2 )
left outer join LocalizedLabelView as "LL3" on ("LL3".ObjectId = "savedquery0".SavedQueryId and "LL3".LanguageId = @LanguageId3 and "LL3".ObjectColumnName = @ObjectColumnName3 )
where
("savedquery0".SavedQueryId = @SavedQueryId0)',N'@LanguageId0 int,@ObjectColumnName0 nvarchar(4),@LanguageId1 int,@ObjectColumnName1 nvarchar(4),@LanguageId2 int,@ObjectColumnName2 nvarchar(11),@LanguageId3 int,@ObjectColumnName3 nvarchar(11),@SavedQueryId0 uniqueidentifier',@LanguageId0=1036,@ObjectColumnName0=N'Name',@LanguageId1=1033,@ObjectColumnName1=N'Name',@LanguageId2=1036,@ObjectColumnName2=N'Description',@LanguageId3=1033,@ObjectColumnName3=N'Description',@SavedQueryId0='A2CC2D8E-9768-DD11-B1B0-00155D869F00'
go
So if we do what i told in the beginning of the post and return some objecttypecode that the method expect the error will not going to happens.
But what is the side effects or consequences?
Because we changed the typecode for that specific view only, then all of the consequences should be on that view which is: You can not search the "Price list items" anymore but still you can sort or use the filters. Personally i think most of users not using that search very often, or maybe i'm wrong don't know.