web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Bring your code 2 life / CRM 2013: fn_GetLocalizedLa...

CRM 2013: fn_GetLocalizedLabel in custom CRM SQL Report and LabelTypeCode parameter

Andreas Cieslik Profile Picture Andreas Cieslik 9,267
Today I tried to migrate a custom CRM 4.0 SQL report to the a CRM 2013 SQL report.
In the report designer I hit the preview button and received the following error:

TITLE: Microsoft SQL Server Report Designer
------------------------------
An error occurred while executing the query.
An insufficient number of arguments were supplied for the procedure or function dbo.fn_GetLocalizedLabel.

OK, this means the SQL function "fn_GetLocalizedLabel" in CRM 4.0 used to have one parameter less than in CRM 2011 or CRM 2013.

After comparing the paramter signatures with the SQL database version I found this definition:

function [dbo].[fn_GetLocalizedLabel] (
    @
ObjectId uniqueidentifier,
    @
ColumnName nvarchar(255),
    @
LabelTypeCode int,
    @
LanguageCode int
)
returns nvarchar(255)
as
begin
   
declare @LocalizedLabel     nvarchar(255)
   
   
begin
       
select @LocalizedLabel = l.Label
           
from LocalizedLabelView l
           
where @ObjectId = l.ObjectId
           
and @LanguageCode = l.LanguageId
           
and @ColumnName = l.ObjectColumnName
           
and @LabelTypeCode = l.LabelTypeCode
   
end
   
return @LocalizedLabel
end

The missing parameter was the "LabelTypeCode".

So I thought what in the world do I have to put in here??
I search in Google and even the CRM SDK documentation does not tell us what this parameter means.

Finally, my last resort is usually to check the CRM assemblies with a Reflector or JustDecompile tool to find out how to deal with this.

Immediately I found this:

namespace Microsoft.Crm.Metadata
{
   
public enum LabelTypeCode
   
{
       
[EnumIntroducedVersion("5.0.0.0", true)]

       
Entity,
       
[EnumIntroducedVersion("5.0.0.0", true)]

       
Attribute,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
AttributePicklistValue,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
EntityRelationshipRole,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
SavedQuery,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
Form,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
FormTab,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
FormSection,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
FormCell,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
SavedQueryVisualization,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
OptionSet,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
Solution,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
Publisher,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
Ribbon,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
TimeZoneDefinition,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
TimeZoneLocalizedName,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
WebResource,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
ManagedProperty,
       
[EnumIntroducedVersion("5.0.0.0", true)]
       
ComplexControl,
       
[EnumIntroducedVersion("6.0.0.0", true)]
       
Workflow
   
}
}

Checking the LocalizedLabelView in the database I only found this information regarding the Labels (truncated data and columns for readability):


LocalizedLabelId
LocalizedLabelRowId
LanguageId
ObjectId
ObjectColumnName
Label
LabelTypeCode
ComponentState
IsManaged
E9158B76-…
7EDC933C-…
2052
C341B506-…
DisplayName
其他
2
0
1
F4F48DB1-…
5B90A8A8-…
2052
CDA38168-…
Description
地址 1 的送货方式。
10
0
1
C97111AD-…
063C23C1-…
1033
8734A095-…
Description
Position of the Sdk
message response field
1
0
1

As you can see the LabelTypeCode contains integer values. But without the enum displayed above the table information would be meaningless as we do not know the purpose of the integer values.

Short reminder:
Enum values start to count from 0.
Meaning that Entity has the number 0, Attribute is 1 ...

This maps to this table:

LabelTypeCode
Integer
Entity
0
Attribute
1
AttributePicklistValue
2
EntityRelationshipRole
3
SavedQuery
4
Form
5
FormTab
6
FormSection
7
FormCell
8
SavedQueryVisualization
9
OptionSet
10
Solution
11
Publisher
12
Ribbon
13
TimeZoneDefinition
14
TimeZoneLocalizedName
15
WebResource
16
ManagedProperty
17
ComplexControl
18
Workflow
19

I hope this helps you to get a better understanding as well in any case you ever need to work with the LabelTypeCodes.

This was originally posted here.

Comments

*This post is locked for comments