3

I'm retrieving a taxonomy field from a search request in a Display Template. The content of the field looks like this:

termField.inputValue
"GP0|#f76c1099-c0e6-f6df-7814-cc7ea541b129

L0|#0f76c1099-c0e6-f6df-7814-cc7ea541b129|The-term-name

GTSet|#49cbba15-ddc7-41ed-8a84-54426c040012"

So now I want to render the system name ("The-term-name") and the label of the term. What is the best approach to do that? Do I have to parse the string value on my own?

2 Answers 2

2

Assuming you only want to parse the returned term and not lookup alternate labels and such you can use the built-in $getItemValue function. It takes the context and the mapped name of your managed property:

$getItemValue(ctx, mappedManagedProperty')

The mapping is the name you specify in the ManagedPropertyMapping attribute within the display template. Say your display template specified these mappings:

<mso:ManagedPropertyMapping msdt:dt="string">
  'Title':'Title',
  'Path':'Path',
  'Description':'Description',
  'EditorOWSUSER':'EditorOWSUSER',
  'LastModifiedTime':'LastModifiedTime',
  'CollapsingStatus':'CollapsingStatus',
  'DocId':'DocId',
  'HitHighlightedSummary':'HitHighlightedSummary',
  'HitHighlightedProperties':'HitHighlightedProperties',
  'FileExtension':'FileExtension',
  'ViewsLifeTime':'ViewsLifeTime',
  'ParentLink':'ParentLink',
  'FileType':'FileType',
  'IsContainer':'IsContainer',
  'SecondaryFileExtension':'SecondaryFileExtension',
  'DisplayAuthor':'DisplayAuthor',
  'ServerRedirectedURL':'ServerRedirectedURL'
  'Subject': 'owstaxIdSubject'
</mso:ManagedPropertyMapping>

Where owstaxIdSubject is a taxonomy field managed property with a value like so:

"SharePoint|#f76c1099-c0e6-f6df-7814-cc7ea541b129

You would write this:

$getItemValue(ctx, 'Subject')

to render something like this:

SharePoint
0

You can get the term and its information by Managed Metadata API (very slow) or lookup in the local list (unsupported). But I'd make a REST call to the item and get directly this fields display value. In that way you do not need to handle different field types and scenarios.

1
  • I already have the term field at hand. It's an JavaScript object of type "Srch.ValueInfo". And the only useful stuff is the property "InputValue" as described in my question. When I want to get the display name I have to use the Taxonomy API, I think that's right. But what's the best way to get the system name that's already contained in "inputValue"? IsN't there any build in function or have I do the parsing on my own? Am I the first person that is obtaining a taxonomy field via a Search Web Part with Display Template?! Mar 4, 2016 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.