locked
Sharepoint 2013 Managed Properties in Search Template RRS feed

  • Question

  • I have a Sharepoint 2013 search display template working nicely. I wanted to add a new managed property mapping to the template which is of type "hyperlink or picture". This content type stores both a URL and description. It returns a comma separated value of link and description (ie. http://www.yahoo.com, my description). Not sure how to grab the link and description individually using $getItemValue from within the template? Any pointers or examples would be much appreciated!
    Monday, June 3, 2013 1:52 AM

Answers

All replies

  • Hi,

    Use javascript :)

    var link = $getItemValue(ctx, "Link");
    var pair = link.split(',');
    var url = pair[0];
    var desc = pair[1];
    

    Thanks,
    Mikael Svenson


    Search Enthusiast - SharePoint MVP/MCT/MCPD - If you find an answer useful, please up-vote it.
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

    • Marked as answer by DirtyShoe Monday, June 3, 2013 7:08 PM
    Monday, June 3, 2013 5:53 PM
  • Thanks. I was looking too deep for a sharepoint solution, forgot about the obvious.
    Monday, June 3, 2013 7:09 PM
  • I am having a similar issue and this code does not solve it.

    I am pulling in a URL field with Description like above ("Yahoo.com, My Description"), but the Description portion of the field does not get pulled.

    I reference the URL field in my managed property mapping, and then get the item value as follows;

    var line1 = $getItemValue(ctx, "Line 1");

    but when I attempt to split it, it errors and says split cannot be used on the object.  This makes sense since it is creating an object, not a string with getItemValue.

    If I console.log the object (line1), it only shows the URL, no description.  So it would appear as if during getItemValue it only grabs the URL portion.

    If I run the code

    var pair = line1.toString().split(',');

    then it lets me convert to a string and split it, but since the string didn't appear to have a ", My Description" the second variable is left undefined.

    Any idea why it doesn't seem to pull in both the URL and Description for me?

    Friday, June 21, 2013 6:41 PM
  • Hi,

    I think it might be a Uri prototype object. Try:

    line1.get_uri() and line1.get_name() or line1.get_title()

    You can always attach a javascript debugger (eg. IE devl toolbar) and examine the object and the methods it provide to find the exact method.

    Thanks,
    Mikael Svenson


    Search Enthusiast - SharePoint MVP/MCT/MCPD - If you find an answer useful, please up-vote it.
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

    Friday, June 21, 2013 8:54 PM
  • I am having a similar issue and this code does not solve it.

    I am pulling in a URL field with Description like above ("Yahoo.com, My Description"), but the Description portion of the field does not get pulled.

    I reference the URL field in my managed property mapping, and then get the item value as follows;

    var line1 = $getItemValue(ctx, "Line 1");

    but when I attempt to split it, it errors and says split cannot be used on the object.  This makes sense since it is creating an object, not a string with getItemValue.

    If I console.log the object (line1), it only shows the URL, no description.  So it would appear as if during getItemValue it only grabs the URL portion.

    If I run the code

    var pair = line1.toString().split(',');

    then it lets me convert to a string and split it, but since the string didn't appear to have a ", My Description" the second variable is left undefined.

    Any idea why it doesn't seem to pull in both the URL and Description for me?

    Hey,

    Pair is an array :) cause return value of split is an array

    you have to say

    if line 1 is ("Yahoo.com, My Description")

    var _marray = line1.split(',');

    even better check for null!!

    if(_marray && _marray.lenght>0){

    var ret_one=line1.split(',')[0];

    var ret_two=line1.split(',')[1];

    }

    Tuesday, June 25, 2013 9:21 PM
  • When I created a url column, and use a content by search to show the column. It only returns the url for me. We have not been able to return the description. I have read that it is not a crawled property?

    Any thoughts?

    Jay

    Wednesday, October 21, 2015 2:38 PM
  • Hi Jay,

    Try using the SharePoint 2013 Query Tool from codeplex and inspect the value returned in your managed property. This way you can see if it has both description and url.


    Thanks,
    Mikael Svenson - Search Enthusiast
    SharePoint MVP/MCPD/P-TSP - If you find an answer useful, please up-vote it. http://techmikael.blogspot.com/
    Author of SharePoint Search Queries Explained and Working with FAST Search Server 2010 for SharePoint

    Wednesday, October 21, 2015 6:18 PM
  • Hi Mikael

    I have the same problem as Jay, the description is not retrieve with the managed property, only the URL. Any Ideas?

    Thanks, Octavian

    Wednesday, November 28, 2018 8:04 AM