Gravatar for ed.kapuscinski@berndtgroup.net

Question by ed kapuscinski, Aug 14, 2014 5:53 PM

What is the Sitecore field name for "template name"?

I'm trying to populate a computed field based on an item's data template using the code sample from the developers site. The IIndexableDataField always comes back null whenever I try any variation of "template name".

I've tried: pIndexable.GetFieldByName("template name") pIndexable.GetFieldByName("templatename") pIndexable.GetFieldByName("_templatename")

What's the real name of the value to get? It's really confusing with the way the field name aliases get hashed into the fields inside the index.

2 Replies
Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Aug 15, 2014 7:21 AM

Hi Ed,

You should use p_Indexable.BuiltinFields.TemplateName; All the 'basic' fields such as template, language, database etc. are coming from BuildInFields.

Gravatar for ed.kapuscinski@berndtgroup.net

Answer by ed kapuscinski, Aug 25, 2014 1:46 PM

I've now tried that, but the IIndexable variable doesn't have a set of properties under called BuiltinFields.

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Aug 25, 2014 1:50 PM

You need to cast the IIndexable into a SitecoreIndexableItem, and then cast this item into a IIndexableBuiltInFields to access it.

Gravatar for ed.kapuscinski@berndtgroup.net

Comment by ed kapuscinski, Aug 25, 2014 5:10 PM

I'm not sure what you mean. Is there a code sample floating around somewhere?

Gravatar for vseguin@coveo.com

Comment by Vincent Séguin, Aug 25, 2014 5:21 PM

SitecoreIndexableItem item = p_Indexable as SitecoreIndexableItem;

IIndexableBuildInFields fields = item as IIndexableBuildInFields;

string myTemplateName = fields.TemplateName;

Gravatar for ed.kapuscinski@berndtgroup.net

Comment by ed kapuscinski, Aug 26, 2014 3:48 PM

That was helpful, but contains a typo. It is actually "IIndexableBuiltinFields" instead of "IIndexableBuildInFields".

Ask a question