0

I'm trying to make a relatively simple change to all search results (for a specific site collection), in order to display the content type of each result. I'm doing this with a change to Item_CommonItem_Body.html and I'm finding that while it works fine for some content types, it displays nothing on others, seemingly just the Office docs.

I've added SPContentType to the list of Managed Property Mappings:

...DisplayAuthor', 'SPContentType':'SPContentType'</mso:ManagedPropertyMapping>

And then I've added the following into the body of the html:

<div>Content Type: _#= ctx.CurrentItem.SPContentType =#_</div>

My test document set includes a number of different file types, each with a number of different content types, and while the text "Content Type: " shows up for all of them, the javascript variable SPContentType is coming through as an empty string for files which are office documents.

If I look at the files in question in their libraries, they have a couple of different content types set (some are "Document", some are custom content types we've created), but none will show their content type.

Has anyone else encountered this issue, or know how to resolve it?

1

I would use the ContentType managed property instead. It is mapped to Basic:5 which I think solves the Office Document issue. It's also marked for "Retrieve" which may also be the issue.

  • Thanks. The problem I have found with ContentType is that it is mapped to both Basic:5 (which is the Mime Type) and ows_ContentType (the actual Content Type), and will return both of them concatenated with a newline or two. – Tyr Jan 20 '14 at 14:12
  • True, you can change that behavior by altering the mapping order and returning only a single value in your own Managed Property – Matthew McDermott Jan 20 '14 at 18:02
1

Annoyingly, this problem seems to have fixed itself the next time I did a Property Sync operation (by going to the Result Types options in Site Settings). I say annoyingly, because it still doesn't really explain what the problem was, or why it only affected some Content Types and not others.

Property Sync

I would suggest (for anyone else with similar problems) that if you try to insert additional parameters into item_commonitem_body.html and have problems, that you subsequently make a parameter change to another template, in order to get the system to prompt you to do a property sync, as it doesn't notice when you've just changed the common item's mapped properties.

Also, if no data is coming through on the mapping, try adding the property into the query (as a sort field works nicely) in order to kick it into retrieving the data properly.

  • 1
    This is a known issue. If you add a new managed property to the Display Template you may need to update the properties on the Managed Result Type page. – Matthew McDermott Jan 20 '14 at 14:24
  • But when you add a property to the common template, it doesn't tell you that you need to update the properties. But by editing a different template you can get it to notice and give you the update link. – Tyr Jan 20 '14 at 14:54
  • Right, that's the problem. As a builder of these I am in the habit of checking there when I notice that the field is not being populated. I have seen some PowerShell to test for "Needs Publishing" but have not gotten it to work consistently. My hunch is there are timers and Content Processing in play that make the timing flaky. – Matthew McDermott Jan 20 '14 at 14:59
  • @MatthewMcDermott, same here. Have tried to automate the "Click" but have not succeeded – Robert Lindgren Jan 20 '14 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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