Tuesday 8 December 2015

SharePoint Managed Property values have spaces

Problem:


SharePoint Managed Property values have spaces and your search results web part does not work!

e.g

StatusOWSCHCS="Assigned"

the url

http://<your server>/pages/finder.aspx#Default={"k":"AssessmentStatusOWSCHCS=Assigned","r":[]}

and anchor tag you create
<a
href='#Default={"k":"AssessmentStatusOWSCHCS=Assigned","r":[]}'

id='View_Assigned'

>Assigned </a>

but for this one


StatusOWSCHCS="Assigned To User"

following will not work

<a
href='#Default={"k":"StatusOWSCHCS=Assigned To User","r":[]}'

id='View_Assigned_To_User'

>Assigned </a>

Fix:


When your SharePoint Managed Property is has spaces in its values then you need to use following java script to construct the URL

var valueTo ='{"k":"StatusOWSCHCS=\\"Assigned To User\\" ","r":[]}';
var encoded= encodeURIComponent(valueTo);
$('#View_Status').prop('href', "#Default=" + encoded);

where View_Status is an anchor tag like this :

 <a href='#'    id='View_Assigned_To_User'  >Assisgned </a>

1 comment: