Sharepoint 2013 Managed Properties in Search Template
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!
June 3rd, 2013 4:52am

Hi,

Use javascript :)

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

Thanks,
Mikael Svenson

Free Windows Admin Tool Kit Click here and download it now
June 3rd, 2013 8:53pm

Thanks. I was looking too deep for a sharepoint solution, forgot about the obvious.
June 3rd, 2013 10:09pm

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?

Free Windows Admin Tool Kit Click here and download it now
June 21st, 2013 9:41pm

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

June 21st, 2013 11:54pm

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];

}

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2013 12:21am

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

Other recent topics Other recent topics