SharePoint 2013: Getting lookup column values in JSLink

Hi Friends,

While working on of the development requirement related to JSLink I came across a scenario where a lookup value needed to be shown in a list view web part.

I wanted to demonstrate with following code how we can achieve to show the lookup values form single valued or multi valued lookup.

Before that I would like to show the relationship between the lists I used to show the demonstration.

I have created following two custom lists for demonstration.

First list with following column –

TestList2

 

The content in First list will like something –

TestList2Content

Second list having lookup column from first list –

TestList1

 

The content in second list like following –

TestList1Content

Following code will show how to get the single or multi valued lookup values and show.


(function () {

var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Item = CustomPortalPageItem;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function CustomPortalPageItem(ctx) {
var html = "";
html += '<div title="' + ctx.CurrentItem.Title + '"></div><div>'+GetLookupValues(ctx.CurrentItem.Test11,"lookupValue")+'</div>';
return html;
}

function GetLookupValues(inputArry,originalColumnName)
{
var retHtml="";
if(inputArry!=null)
{
for(var loopcnt=0;loopcnt<inputArry.length;loopcnt++)
{
if (typeof(inputArry[loopcnt][originalColumnName]) != 'undefined' && inputArry[loopcnt][originalColumnName] != null)
{
retHtml+=inputArry[loopcnt][originalColumnName];
}
}
}
return retHtml;
}

After this it will look like following,you can then apply beautiful HTML to it.
JSLInkOP

SharePoint 2013: Designer workflow error with ‘Call HTTP web service’ action

February 17, 2015 4 comments

While working on one of the workflow development task, it was required to have a web service call to fetch data from SharePoint. To achieve that I used ‘Call HTTP web service’ action but with that I was getting following exception “Unable to deserialize HTTP response content. Expected Content Type: ‘application/json’, ‘text/plain’ or ‘text/html’”.

Suspended

After struggling with this issue, the solution I used thought to share the solution with developer community.

Solution: The reason for the issue is, by default response from SharePoint REST is in XML and SharePoint designer workflow not able to parse the xml and needs JSON response. To resolve this issue we need to pass Accept and Content-Type as application/json;odata=verbose to request headers. This way we will get JSON response. To resolve this follow bellow steps.

  1. Go to SharePoint 2013 designer.
  2. Build a Dictionary variable named ‘WSHearder’WF1
  3. Add two values in newly created dictionary
Accept = application/json;odata=verbose
Content-Type = application/json;odata=verbose
WF2
  1. Now select ‘Call HTTP web service’ action and select Properties.              WF3
  2. Select newly created dictionary variable as value for ‘RequestHeaders’.WF4
  3. Press OK and publish the workflow.

SharePoint 2013: Querying SharePoint log files

December 31, 2014 Leave a comment

Hi Friends,

While working as a SharePoint developer every one of us need to go to SharePoint log files to check exact nature and cause of error. SharePoint logs provide us vital information to resolve the issue. SharePoint provides us correlation id to get the details about the issue, but it is difficult some times to go and check the log files and manually find the error in log and get the cause, as log files are huge sometimes.

To resolve this we have some PowerShell cmdlets which we can use to search in log files. Some of them are Get-SPLogEvent and Merge-SPLogFile. We can discuss about them in more detail below.

1. Get-SPLogEvent-

We can use Get-SPLogEvent to query log files when either single server farm in place or we have knowledge on which server the error gets logged.So Get-SPLogEvent will query the logs in the same server where PowerShell command gets executed.Some of the samples below –

get-splogevent | ?{$_.Message -like "*Monitored*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log1.log

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the requested fields (Area, Category, Level, EventID, Message) in file Log1.log

get-splogevent | ?{$_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"} | select Area, Category, Level, EventID, Message | Format-List > C:\Log2.log

Above command will search with specified correlation id and dump the requested fields (Area, Category, Level, EventID, Message) in file Log2.log at specified path

You can use the above commands directly also on powershell to get the details directly instead of creating a file out of it, like

get-splogevent | ?{$_.Message -like "*user*" -and $_.Correlation -eq "2713db9c-f21e-e0bc-3393-95ddcbf60bd0" -and $_.Level -eq "Medium" -and $_.Category -eq "App Deployment"} | select Area, Category, Level, EventID, Message

Above command will search with specified correlation id and get the content where message contains ‘user’ word , Level is ‘Medium’ and Category equals ‘App Deployment’ and display the requested fields (Area, Category, Level, EventID, Message) on PowerShell window.

get-splogevent -StartTime "12/11/2014 10:00" -EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and display on PowerShell window.

2. Merge-SPLogFile-

We can use Merge-SPLogFile to query log files when we have a scenario where mult-server farm in place and we do not have idea where exactly the error get logged. i.e. timer service is running on four servers and the current timer request is served by Server1 then error get logged on server1. Some of the samples below –

Merge-SPLogFile -Path "C:\Log1.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and get the content where message contains ‘Monitored’ word and dump the details in file Log1.log

Merge-SPLogFile -Path "C:\Log2.log" -Overwrite -Message "*Monitored*" – Correlation "2713db9c-f21e-e0bc-3393-95ddcbf60bd0"

Above command will search with specified correlation id and dump the details in file Log2.log

Merge-SPLogFile -Path "C:\Log3.log" -Overwrite -StartTime "12/11/2014 10:00" - EndTime "12/12/2014 18:00"

Above command will search the logs with specified date range and dump the details in file Log3.log.
Hope this will reduce some of the debugging efforts.

“As the year comes to an end, don’t look back at yesterday’s disappointment. Look ahead to God’s promises yet to unfold.” ― Buky Ojelabi, comtemporary blogger
Happy new year 2015.

SharePoint: Using Papercut for testing the email functionality in SharePoint.

October 31, 2014 Leave a comment

In many scenarios while working with SharePoint we may come across requirement to test emails. Like email alerts, emails from workflow, timer jobs or event receivers etc. In my case I need to test emails from Timer job.
While development phase it is not always possible to have a SMTP sever available to test those kind of functionality and in those scenarios Papercut is best utility available for our help. Papercut is a simplified SMTP server designed to only receive messages and serve the purpose of light weight SMTP.
You can use Papercut in .Net development or SharePoint development. You just need to download and install the Papercut on your SharePoint server.

Papercut-v3.1.0-S1
Some points to consider while using Papercut with SharePoint-
1. Papercut is only to receive emails.
2. In case of ASP.Net application provide host=”127.0.0.1″ port=”25″ in web.config file under mailsettings section.
3. For SharePoint, If you have single server farm then you don’t need to worry just install Papercut and set the ‘Outbound SMTP Server’ to localhost or 127.0.0.1 in ‘Configure outgoing e-mail settings’ under central admin, System settings.
4. You can now test by creating simple alert on any list.
5. If you have muti-server farm and testing email from timer job then need to find on which server timer service is running and on that sever you need to install Papercut also give this server IP in ‘Outbound SMTP Server’ in ‘Configure outgoing e-mail settings’ under central admin, System settings.
6. If timer service running on more than one server then make sure port 25 open between those servers to get emails from timer job.
Hope this will help.

Note: complete contribution, development and license rights are with the team who have developed this and as per the http://papercut.codeplex.com/license . This post is just to make readers aware that this kind of tool exists.

SharePoint 2013: Item template not called in JSLink with group rendering

July 10, 2014 3 comments

Hi Friends,

I have explained the Group rendering with JSLink in one my previous blog. I will explain a common problem and a solution for that while group rendering with JSLink.

Scenario:

While rendering grouping in view with JSLink, We normally face an issue that item rendering handler ‘overrideCtx.Templates.Item’ is not getting called. Group rendering was working fine in my case but not item level rendering.

Solution:

Initially I thought something wrong with JSLink file but after analysing and debugging I found the problem is with the grouping configured in data view.

To fix this issue edit your data view and go to grouping section of the view. Change ‘By default, show groupings’ setting to ‘Expanded’ and save the view and bingo it will start working.

Following image shows the setting in data view –

JSLink Group

JSLink Group

If you are provisioning data view declaratively then you need to add Collapse=”FALSE” to your <GroupBy node.

JSLink_Group1

Possible reason for this problem is, while the groups shown in collapsed state item in that group are not loaded initially and once you click to expand the group it will be loaded on demand hence item template not gets called initially as items not loaded.

Hope this will help some of the developer looking for same kind of answer.

Happy coding!!!

SharePoint 2013: Friendly URL’s in Publishing HTML Field is broken and showing FIXUPREDIRECT.ASPX as hyperlink in display template

June 12, 2014 4 comments

Hi Friends,

I came across a weird scenario recently, thought to share here so that it will be helpful for some of our friends.

Scenario:

In one of the article page we were having a Publishing HTML Field, content author added relative friendly URL as a hyperlink inside the field.  I.e. help/ithelp/lync

This page was supposed to be crawled and this Publishing HTML Field’s search managed property was used to display the column data in a search display template in content search web part (CBS).

The result displayed in content search web part was perfect except some of the hyperlinks are pointing to wrong pages.

The URL’s were pointing to FIXUPREDIRECT.ASPX page with some GUID’s as query string like following.

/_layouts/15/FIXUPREDIRECT.ASPX?WebId=1230beb8-10d2-46a2-b768-94948b2ea947&TermSetId=cebe5639-ae8c-4225-ab3b-aeb1a81fb09d&TermId=cec1896c-16e2-410f-a1f9-6b084e3b9890

Analysis of the issue:

After analysing the issue for couple of hours found that it is something related to managed metadata terms as the query string formed had termsetid and termId as query sting parameters.

Also we found that only the friendly URL’s ware broken. The magic happening while the page is getting saved and SharePoint tries to resolve the friendly URL with available terms and replacing the URL with FIXUPREDIRECT.ASPX URL and same gets crawled. It is nothing to do with search display template.

Workaround:

We tried to find out the solution to resolve this issue but no luck; we have tried workaround to replace the friendly relative URL with non-friendly URL and it worked for us.

help/ithelp/lync   TO   help/ithelp/lync.aspx

 

SharePoint 2013: Display template in content search web part not retaining selection

March 27, 2014 3 comments

Scenario: While adding content search web part in a page or page layout using all user web part. The selected display template while exporting web part is not retained the selection of custom display template and default display template gets selected if we create new page out of the page layout or page. I have verified couple of times in all user web part and it is correctly pointing to the display template like following-

~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Test_Item_Contacts.js

before_change

Solution:  Found out the problem with ~ symbol and solution is to replace it with ASCII equivalent & # 126 ; (Remove space)

~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Test_Item_Contacts.js

After_change