0

I have a simple list with a column of type 'Hyperlink or Picture' named 'TestHyperlink'. I've created a Managed Property at the Search Service Application screen for this column so it can be used later inside a Search Template. I do an index reset and fully crawl to make sure the system is aware of my newly created property.

Inside the Search Template I add the property to the ManagedPropertyMapping tag and create the following line:

console.log(ctx.CurrentItem.TestHyperlink)

The log shows me the url but not the description. I've read on the Internet it should return a csv value like this: 'url, description' but not in SP2016.

So my question in short; how can i get the description out of a 'Hyperlink or Picture' column in SP2016?

2
  • You don't need to do the index reset. I'll do a test and look for an answer for you. – Matthew McDermott Feb 6 '17 at 11:26
  • That would be very nice of you. Thanks in advance! – JonasVH Feb 6 '17 at 14:19
0

Try:

console.log(ctx.CurrentItem["TestHyperlink.desc"]);

or also, maybe:

console.log(ctx.CurrentItem.TestHyperlink.desc);
3
  • Thanks for your reply but it doesn't seem to work as 'ctx.CurrentItem.TestHyperlink' isn't an object but just a plain string. Therefore it just return 'undefined'. Maybe I'm choosing the wrong Type format while creating the Managed Property? – JonasVH Feb 6 '17 at 8:56
  • What about console.log(ctx.CurrentItem["TestHyperlink.desc"]);? – Evariste Feb 6 '17 at 9:23
  • Nope same thing 'undefined'. – JonasVH Feb 6 '17 at 9:45
0

While waiting for a concrete answer I've used the following work around. I've split column 'TestHyperlink' into two other columns named 'TestHyperlink_Url' and 'TestHyperlink_Desc' formatted as type 'Text'. Afterwards I've created a Managed Property for mapping the new columns. As they are simple text columns it's now possible to use them in my Search Display Template.

0

Doing my own testing the Managed Property associated with the URL field only stores the URL and throws away the Description. In fact, if I search for the description I don't find it, but if I search for the URL I find that. So that means that during content processing it appears that the URL is the only part that is kept.

2
  • Thanks for your input @matthew-mcdermott Guess my workaround is the solution for my problem. – JonasVH Feb 10 '17 at 12:34
  • I would agree, particularly if you want the description searchable. – Matthew McDermott Feb 11 '17 at 12:54
0

You should map your Managed Property to Crawled property ows_q_URLH_TestHyperlink.

Then your managed property will contain URL and description in format: "Url, Desc".

Then, in display template you can add some js to extract this url\description:

var UrlFull = ctx.CurrentItem.YourManagedProperty;
var UrlPath = (UrlFull .split(','))[0];
var UrlDesc = (UrlFull .split(','))[1];

to build hyperlink for example:

<div>Link: <a href="_#= $htmlEncode(UrlPath) =#_"> _#= UrlDesc =#_ </a></div>

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.