Managed properties in display templates

Hi

I'm trying to include some custom managed properties (GlossaryProductString) into my custom display template but the ct.CurrentItem.GlossaryProductString is always undefined.

What I did:

  •  Create managed property and mark it as retrievable
  • Full crawl (I'm able to find results when using GlossaryProductString:"some content" as query)
  • Downloaded the item_default.html and renamed it
  • Added GlossaryProdcutString to the ManagedPropertyMapping properties ('GlossaryProductString':'GlossaryProductString')
  • Add the content to the template:
    <p>Product: <span style="font-weight: 200">_#= ctx.CurrentItem.GlossaryProductString =#_</span></p>
  • all other stuff that is needed that the display template is used

The display template shows up for the results but the GlossaryProductString is always empty (undefined in JS object)

Any ideas?

Thanks for help.

November 1st, 2012 10:05am

This appears to be a bug. I am seeing the same
Free Windows Admin Tool Kit Click here and download it now
November 1st, 2012 9:59pm

Perhaps you can find something useful in the documentation for configuration of the search results web part:

http://technet.microsoft.com/en-us/library/gg549987.aspx

(not exactly the same, I know, but perhaps useful anyway)

November 22nd, 2012 11:33am

Hi there,

Could you verify through the REST API that your managed property really got picked up as retrievable by the index?

http://<url>/_api/search/query?Querytext='GlossaryProductString:"some content"'&RowLimit='10'&SelectProperties='Title,Path,GlossaryProductString'
Free Windows Admin Tool Kit Click here and download it now
November 23rd, 2012 1:12pm

Hi

The REST call returns the GlossaryProductString. Here an excerpt of the result:

- <d:element m:type="SP.SimpleDataRow"> - <d:Cells> - <d:element m:type="SP.KeyValue"> <d:Key>Rank</d:Key> <d:Value>11.5733613967896</d:Value> <d:ValueType>Edm.Double</d:ValueType> </d:element> - <d:element m:type="SP.KeyValue"> <d:Key>DocId</d:Key> <d:Value>725</d:Value> <d:ValueType>Edm.Int64</d:ValueType> </d:element> - <d:element m:type="SP.KeyValue"> <d:Key>Title</d:Key> <d:Value>Argument</d:Value> <d:ValueType>Edm.String</d:ValueType> </d:element> - <d:element m:type="SP.KeyValue"> <d:Key>Path</d:Key> <d:Value>https://sst-s13.ioztest.ch/glossary/Lists/Definitions/DispForm.aspx?ID=8</d:Value> <d:ValueType>Edm.String</d:ValueType> </d:element> - <d:element m:type="SP.KeyValue"> <d:Key>GlossaryProductString</d:Key> <d:Value>Excel</d:Value> <d:ValueType>Edm.String</d:ValueType> </d:element> - <d:element m:type="SP.KeyValue"> <d:Key>OriginalPath</d:Key> <d:Value>https://sst-s13.ioztest.ch/glossary/Lists/Definitions/DispForm.aspx?ID=8</d:Value> <d:ValueType>Edm.String</d:ValueType>

November 26th, 2012 7:50am

Could you configure the Search Results Web Part to "Use a single template to display items" (under the Dislay Templates section) and see if that works better?

It looks like there might be a bug where ManagedPropertyMapping isn't properly picked up across all templates if the default "Use result types to display items" option is selected.

Free Windows Admin Tool Kit Click here and download it now
November 26th, 2012 12:32pm

Thanks!

Using "Use a single template to display items" displays the custom manged properties.

This is great for result source specific result pages. For the "Everything" results the issue still exists, but I can live with this at the moment

November 27th, 2012 8:19am

Hi,

is this still the only way to get additional managed properties into a search display template? Using "Use a single template to display items" isn't possible in all scenarios (for example central search page in a site collection)

Free Windows Admin Tool Kit Click here and download it now
January 16th, 2013 8:33am

Hi,

I am customizing the display template of hover template in search result web part. I am able to display couple of properties using the ctx.CurrentItem.<managed property name> but there are a few properties which are not showing values though they have values. I checked using javascript alert and it shows that these properties are undefined.

In different scenario I customized the 2 lines template of content search web part to make it 6 lines template. I used the same property names in this template and it works.

Any idea where I have gone wrong?

Thanks,

Hemil

January 17th, 2013 4:58pm

Hi,

Anybody find a solution for this?

Kind Regards

Vandeput

Free Windows Admin Tool Kit Click here and download it now
March 26th, 2013 8:16am

Hi Everyone,

I had a similar problem today, I mapped the People:Office field to a custom managed property called "Office", then reset the search index and did a full crawl. I could search using the query "office:north building" and would get correct results, yet adding the property to the managed property mapping in my custom people item hover HTML wasn't working, the variable ctx.CurrentItem.Office was always undefined. The solution was to have the managed property mapping for Office in both the custom people_item template HTML file, as well as in the hover panel HTML file.

Took me a while to figure it out... Hopefully this helps you out!

  • Proposed as answer by ecm_dev Thursday, April 04, 2013 7:35 AM
April 4th, 2013 7:35am

With regards to the Managed Property Mappings not being returned in results when the Script Result Web Part is set to 'Use result types to display items'. I have a workaround for the time being if anyone's interested.

Add a Script Editor Web Part onto the same page where your Script Result Web Part is located and add the code below. You'll want to modify the myProps array with the Managed Properties you want to appear in your results.

<script type="text/javascript">
//<![CDATA[

/*
Injects additional managed properties to search queries
due to a bug with the ResultScriptWebPart where
Managed Properties are not returned for the Display Templates:
http://social.msdn.microsoft.com/Forums/en-US/sharepointsearch/thread/f53c87d0-af81-445c-8338-1bfea6ca780e

Add Manage Property names to newProps array.
*/
function insertSelectedProperties() {
  var newProps = ['ManagedPropName1','ManagedPropName2'],
      groups = Srch.ScriptApplicationManager.get_current().queryGroups;

  for (var x in groups) {
    var group = groups[x],
        props = group.dataProvider.get_selectedProperties();

    Array.forEach(newProps, function(prop) {
      if (!Array.contains(props, prop)) {
        props.push(prop);
      }
    });

    group.dataProvider.set_selectedProperties(props);
  }
}
Srch.ScriptApplicationManager.get_current().add_preLoad(insertSelectedProperties);


/*
This is a bit of a hack as it does a second query on load if there's a search query
string value. Could be removed if we can find a better event to hook insertSelectedProperties into.
*/
function doSelectedPropertiesSearch() {
  var groups = Srch.ScriptApplicationManager.get_current().queryGroups;

  for (var x in groups) {
    var group = groups[x];

    Array.forEach(group.searchBoxes, function(box) {
      if (box.get_currentTerm() != '') {
        box.search(box.get_currentTerm());
      }
    });
  }
}
Srch.ScriptApplicationManager.get_current().add_postLoad(doSelectedPropertiesSearch);

//]]>
</script>

An added benefit is that if you have a shared property across all your results types that you want to display,  you no longer have to modify the Managed Property Mappings field on all the OOTB Display Templates.


  • Edited by Sing Chan Thursday, April 04, 2013 5:16 PM
Free Windows Admin Tool Kit Click here and download it now
April 4th, 2013 5:16pm

If i add this script in the search result page, the page is loading and refreshing infinite times.

May i know the reason?

May 6th, 2013 8:23pm

Hi,

are there any updates on this issue? Is it a known bug that can be expected to be fixed with a future update or is there another way to get more Managed Properties into your Search Results?

I would like to keep the dynamic Display Template matching logic without modifying every Item Template and disabling the whole dynamic part by switching to a single template isn't a solution for me either.

The solution from Sing Chan works fine but I don't think that this would be your default approach to add more Managed Properties to your result... ;)

Kind Regards

Sebastian

Free Windows Admin Tool Kit Click here and download it now
May 17th, 2013 7:04am

If you are using an Item Display Template attached to a Result Type, you will have to ensure the Result Type has been synced before the Managed Properties become available.

See this blog post from Steve Mann for details.

May 30th, 2013 6:04pm

Hi

I have tried Sing Chan's code in a SharePoint 365 (Wave 15) search site collection, inserting it as a script into a script editor web part on the same page as the Results Web Part.  Unfortunately, it would appear not to work.   ie the managed properties were not surfaced into the Display Template.

I used JobTitle and BaseOfficeLocation as the managed properties.  Both are managed properties, mapped to the appropriate crawled properties.

Anybody got any ideas ?

Regards

Nigel

Free Windows Admin Tool Kit Click here and download it now
June 9th, 2013 11:40pm

Hi,

I was fiddling around a bit with Result Type synchronization and it looks like there needs to be a Result Type at the same lavel that is referencing a Display Template with recent changes.

For example when I change a Display Template at Site Collection level and try to synchronize Result Types I don't see the sync bar. But when I create a Result Source at the same level and make changes to a Display Template that is referenced by it I am able to sync my Result Types.

Do I really have to create a Site Collection Result Type referencing the template I want to change to be able perform a synchronization? I don't have Site Collection Result Types and am using the ones provided by the Search Service so could it be that SharePoint is unable to synchronize changes because of this?


Kind regards
Sebastian

June 18th, 2013 12:31pm

From my experience you don't need to create a result type for this. 

As long as your html and associated java script files are in sync you are good to go.

Please check you java script file is synchronizing when you make changes in the html display template file. if not there is problem in your server. 

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2013 2:28pm

Hi,

html and js files are syncing just fine. It's only that I am unable to sync Result Types unless I create a new Result Type referencing the template I want to change.

So for now it seems like I'll have to stick with that solution... :/


Kind regards
Sebastian

June 19th, 2013 6:06am

Hi

does anyone know when the original big ie custom properties not being displayed in display templates will be fixed ?

This has been outstanding now for nearly none months.

thanks

Nigel

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2013 11:45am

This blog post from Steve Mann is very helpful and now my managed properties are showing up fine in the results

August 14th, 2013 12:45am

Which Steve Mann blog post ?
Free Windows Admin Tool Kit Click here and download it now
August 14th, 2013 4:38am

Excellent!! done the wonder.. am breaking my head for 2 days and this helps alot. Thanks dear
August 27th, 2013 9:42pm

These posts only deal with custom Result Types as far as I can tell. This is very frustrating...I cannot recreate 31 result types just to add an extra field!
October 21st, 2013 3:56pm

I can't get this solution to work.
Free Windows Admin Tool Kit Click here and download it now
October 21st, 2013 4:05pm

Hi

This is working for me now.

Regards

Nigel

October 21st, 2013 4:11pm

Thanks!

Using "Use a single template to display items" displays the custom manged properties.

This is great for result source specific result pages. For the "Everything" results the issue still exists, but I can live with this at the moment

I think I have a great workaround for this. You can add new Managed Properties to the OOTB Display Templates, they just won't be picked up in the default Result Types. What I've been doing is simply copying each Result Type (which is a drop-down option) for my Search Center's site collection that I need new Managed Properties on and I'm able to grab the new properties through my modified OOTB display templates.

Obviously this is tedious manual work (which I think is goal #1 of a software developer's list of things to eliminate) and I'm looking into programmatically packaging this up as a feature. The only downside I see to this approach is the wasted man hours copying the Result Types if a fix to this is released. I'm still waiting for this magic October fix that will fix the Office Metadata crawler which incorrectly indexes the titles of Word/PPT documents so I'm not too hopeful.

I think this approach is much more efficient and safer than the JavaScript posted in this thread, with all due respect to Sing Chan. I very much admire the effort put into discovering how to approach this and digging in so deep put in that approach. However, it did not allow me to run OnPost JavaScript functions at the Display Template level.


  • Proposed as answer by WackyDellyYeah Wednesday, October 23, 2013 1:43 PM
  • Edited by WackyDellyYeah Wednesday, October 23, 2013 1:46 PM Clarity
Free Windows Admin Tool Kit Click here and download it now
October 23rd, 2013 1:43pm

It's the last day of October, has anyone found the fix to actually display the library titles for word/ppt documents?  I looked through the October CU but I didn't see that mentioned anywhere. 

Thanks. 
October 31st, 2013 2:57pm

It's the last day of October, has anyone found the fix to actually display the library titles for word/ppt documents?  I looked through the October CU but I didn't see that mentioned anywhere. 

Tha
Free Windows Admin Tool Kit Click here and download it now
October 31st, 2013 3:00pm

Yeah if you could post the work around that would be great.  Thanks. 
October 31st, 2013 4:13pm

Finally after wasting much time. Found this. Thanks.
Free Windows Admin Tool Kit Click here and download it now
December 27th, 2013 5:03am

Hi,

using tis script causes, that the links from search result (e.g. to a document) are not working any more.

It causes 404 error.

Any idea to avois the error?

March 17th, 2014 2:36pm

today, after changing the managed property mapping in display template, i did not see the yellow message bar to prompt me to sync the change. And i don't know other approach to trigger the sync.

I unchecked the Optimize for frequent use option in result type, seems that this can also fix the issue

http://techmikael.blogspot.com/2014/08/optimize-for-frequent-use-setting-in.html

Free Windows Admin Tool Kit Click here and download it now
December 26th, 2014 2:10am

I have noticed, manage properties giving some challenges and resolved after doing a reset SharePoint configuration cache.  give a try with that. you can find plenty of post how to reset the SharePoint config cache.

June 22nd, 2015 1:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics