Tuesday, 25 April 2017

Showing Blog Post’s Comments and Likes Count in Content Search webpart

In SharePoint 2013 OnPremise, we had one requirement recently to show Comments and Likes count with each blog post in Content search webpart. We have two different Sharepoint Web Applications (different domains with different AD), and we were required to show this web part on both these applications front page. Also one important thing to note is that we have only one “My site” for both the applications.

Based on customer requirement, first we implemented this only for first web application.

During this implementation, we found that Likes count implementation was pretty straight forward (using “LikesCount” managed property, in display template, mapped to “ows_LikesCount” crawled property). The continuous or incremental crawl updates this property correctly (for continuous crawl it takes around 3 mins interval to update).

But we found that this wasn’t the case with Comments crawled property “ows_NumComments”. Though we created a managed property for it, say NumComments, it still wasn’t updating the comments counter after continuous or incremental crawl. It requires a Full crawl all the time to update the counter. We also found this issue mentioned here.

Comments counter (# Comments) column is not created as Site Column. It is local in Posts library.

To set it in Full Crawl, we can set “My Site” in new Content Source and set it to run every 3 or “x” mins.

But setting a Full crawl for updating only one field wasn’t our choice that time (considering performance overhead for whole application) so we decided to fetch Comments count with the help of REST calls from display template. For this to work with cross site (“My Site” was in a different domain), we had to add few entries in web.config of “My Site” to allow cross domain requests from single calling domain:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>



And put following entries inside the “customHeaders” tag:
<add name="Access-Control-Allow-Origin" value="<http://calling-domain>" />
<add name="Access-Control-Request-Method" value="GET, POST, HEAD, OPTIONS" />
<add name="Access-Control-Request-Headers" value="Content-Type, Authorization" />
<add name="Access-Control-Allow-Credentials" value="true" />

This worked great for only single domain for few months. But then there came the new request from Customer to add the same Content search web part on another application front page as well. Now for this cross site REST calls to work with 2 domains (or host-headers) we simply replaced value for “Access-Control-Allow-Origin” to “*” as mentioned in this MSDN blog

<add name="Access-Control-Allow-Origin" value="*" />

But after many unsuccessful attempts, It was concluded that “*” doesn’t work with SharePoint environment, it allows only single domain address for allowing cross site access.

So we decided to again give it a thought on our first approach of using Managed Property for Comments count for only this second application. As in this second application, blog posts are only coming from “My Site” so there was no need to do a Full crawl for the whole second application and it was needed for only “My Site”. So it was a considerable case for Full crawl as we have to do it only for “My Site” and not for those main sites with huge contents and libraries.

We created a new managed property “NumComments” for “ows_NumComments” crawled property and then created a new Content Source which had Full crawl scheduled to run for every ‘x’ minutes interval or so. We have assigned only “My Site” reference in new content source and scheduled to run it for every 30 mins. Earlier we thought it would be a performance overhead, but since we have to do full crawl for only “My Site”, it shouldn’t be a problem.

We kept the approach of using the REST call for first application as it is as there were posts from both the first application and “My Site” as well. So it was not convenient to allow Full crawl for first application because of huge contents.

Conclusion:

So we had to use this mixed approach for fulfilling our requirement (especially for showing Comments count) for both applications.

For First application, we used REST call approach for fetching comments count from Comments list (by adding above Access-Control-Allow-Origin entries in web.config in “My Site”, which works well for single domain)

For Second application, we used Full crawl technique (for only “My Site” set to full crawl) where 30 mins crawling schedule is set for updating NumComments managed property and then shows correct number in webpart.

I hope it will help someone struggling to overcome the similar situation.


Happy Learning! J

Display Default Value in People Picker Control in List New Form

In SharePoint 2010 OnPremise, our Customer came up with one new small requirement to show the default value for people picker control in Custom List OOB New Form. As it was for a simple OOB new form for a Custom List, we analyzed the options accordingly in 2010.

  • If you want to do it in InfoPath Form then there is very nice article presented here by Laura Rogers 
  • If you want to do it in SharePoint 2013 then please refer this nice article which describes how to do it with JSLink.


In our case it was SharePoint 2010 and a Custom List OOB New Form. Actually the problem is we cannot set default values for People Picker control from design time so we had two options basically, one with the help of Custom JQuery Injection or second with the help of third party SharePoint Add-On

We observed following Pros and Cons for the SharePoint Add-On:

Pros:
  • It can be very useful for setting default values during design time for lookup or people picker fields.

Cons:
  • It is not free. Free trial period is only for 30 days
  • Setup will install a new wsp to the farm so might be a problem with maintenance or updates in future


So we decided to go ahead with the first option instead i,e. Custom JQuery Injection approach, that was more simple and quick to implement.
For this we edited the default new form for the custom list, then added one Content editor webpart in the form so as to attach a custom .js file with it (Remember there was no JSLink in SP 2010). Now is the time to create actual JQuery file which will inject default value into the People Picker control.
In our case Customer wanted to show a particular person’s name in the people picker and not the logged in person as default. If you have the requirement to show the logged in user as default then you may refer this link with some little variation and use of “jquery.SPServices” libraries.


We created following JQuery Injection script for our purpose. Here is the custom JQuery script named “setdefaultvalue.js” (I hope you have “jquery.min.js” already available in “_layouts/js” folder in 14 hive, if not you can download it from here and place it in 14 hive path)

setdefaultvalue.js
<script src="/_layouts/js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {

user = "Domain\\Username"; // Set “Domain\\Username” as default user

// Set “user” as default value in the required people picker control
var counter = 0;
$('div[title="People Picker"]').each(function() {

    if (counter == 1) {
        $(this).html(user);
    }
    counter++;   
});

// Call the click event of “Check names” button explicitly
counter = 0;
$('a[title="Check Names"]').each(function() {
   
    if (counter == 1) {
            $(this).click();
    }
    counter++;   
});
});
</script>

Note: In this script we used “counter” variable to check at which position our People Picker control appears in the form (required only in case of multiple People Picker control on form).

And then uploaded this file in that site collection’s Style Library




And then referred it in the Content Editor webpart property “Content Link” as below




Just make sure of one thing, keep the Zone index of the content editor webpart later than the main form webpart. Suppose if main form webpart zone index is 1 then keep the zone index of content editor webpart as 2. This will make sure that all the controls in the form are loaded first and then JQuery script will fire.


After all these steps, default value started showing up correctly in the desired People Picker control on the list new form.



Happy Learning! J

NoteField values not getting crawled in SharePoint 2013

Yesterday, we were working on one new feature in our project where there were new Content Types and Site Columns. Amongst those site columns one field was of type “Note” (Type="Note").

Customer requirement was that we should show this “Note” field in Search Results webpart in second row for each item. So we performed regular procedure for showing this field in search results web part. We created few pages filled with data for all fields(including this Note field) and then ran full crawl. Within some time, managed properties were created under Search  Schema. But they were not set as “Queryable”, “Searchable”, “Retrieveable”,“Refinable”. So we applied those settings and then ran the full crawl again.

After some time when the crawl was done, we checked values from SharePoint Search Query Tool on Server. It showed values for all fields except this “Note” Field. We checked all our configurations again but they were correct. We searched a lot for this issue on google but couldn’t find satisfactory answer for this issue.

Then while performing research, we added few other “Note” columns for testing with different settings and after crawling we observed that in Elements.xml, this setting “UnlimitedLengthInDocumentLibrary” was “False” for this particular Note field where values were showing in search tool and it was “True” for other Note fields where values were missing. This setting, if “True”, actually helps us to increase text length to unlimited characters. And it seems this is the reason why search crawler doesn’t consider crawling it to avoid bad performance and space constraints. We informed it our customer and changed requirement to keep only 255 characters length in “Note” field column.

Ideally Note Field allows only 255 characters and if you want to really allow more text in Note Field then you need to enable this property.

UnlimitedLengthInDocumentLibrary="TRUE"


You can see this setting from Site Settings > Site Columns >> Edit any note field.


Usually in web parts like Search results, CBS etc. we show columns like Title, Image, Url, description etc. and we shouldn’t show big text columns in results. Such columns should be available only in individual Pages (for ex. Content area, Note field etc).

I hope it will help someone out there!

Happy Learning! J

The SOAP message cannot be parsed.

In SharePoint 2010, I had customer requirement to add new fields to the existing InfoPath form for one Custom List with large data. For this I started editing InfoPath form with the tool MS InfoPath Designer 2010 (which comes with MS Office).

To edit the form, you can click on “Customize Form” ribbon button inside the “List” Tab, It will open form in InfoPath designer tool.


I added some new fields to the form and tried to publish the form using either of the below marked actions.



But in design checker it thrown exception “Control binding is not supported” for 3 different calculated value fields. I managed to resolve this issue with the help of this blog.

Again I clicked on “Quick Publish” to publish the form, this time there were no more these above 3 exceptions and now it took long time but publishing failed with following error.

The publish operation could not be completed. It cannot be determined if the form template was successfully published. Try publishing the form template again, or change the list settings to use the default SharePoint form.
-          The SOAP message cannot be parsed.



The exception was not at all leading me to the right direction. When checked the ULS logs there was no specific and helpful error found. There was also no problem with permissions to the list. User was having Full Control.

After googling for some time, following solutions were found for this particular error:

  • Increased the executionTimeout value in web.config and set it to 3600 seconds. But in my case it was already set in web.config <httpRuntime maxRequestLength=”2097151″ executionTimeout=”3600″ />

  • Tried increasing data connection timeout values (to 1 hr) from central administrator for InfoPath Forms Services



  • Checked whether site collection feature “SharePoint Server Enterprise Site Collection Features” is activated. In my case this feature was already activated.


  • Tried updating missing bindings for some dropdown controls
  • Tried with removing all calculated value fields from InfoPath form.
  • Tried changing name of the template.xsn and ID
  • Traced InfoPath form publishing in Fiddler and tried to get answers for exception in response i,e.“Request timed out” with status as HTTP 302. All answers lead to the same above resolutions which were already tried.
  • Tried restoring site collection again
  • Tried with new custom list and for it InfoPath forms publishing was working correctly
  • Tried importing changed/saved template by SharePoint designer and then renamed it. 
  • But it showed the following error when I clicked “Add new item” link
Unfortunately no single option from above helped me.

But after trying all these above options, again I given a thought on “Request timed out” exception from Fiddler. Even though I tried increasing all timeout values above, I was googling more on this issue. After spending lot of time on this, found that few of the blogs mentioned about huge lists cases means list with large number of items and it was true for this list as well. It was having around 4500 items.

So I decided to reduce items batch wise (max 100 at one batch) from the list and let it go to the recycle bin. I was also checking form publishing simultaneously during this process. It was still failing. But as it was gradually decreasing the number of items in the list, it finally reached that level when InfoPath Form Publishing was successful J

The magic number was around 1500 items. When I checked it multiple times, I found that above this level, form was not able to publish. The reason for this may be because Form was containing 25 calculated values and hence publishing was failing for large items.

Now as the reason was known, it was needed (for publishing updated form with new changes) to either move items above 1500 to similar duplicate list and then again move those back OR Delete those items and then restore it back from the recycle bin. That’s It!



Note: FYI, during this process, I faced this different exception as well during publishing
The SharePoint list form can't be customized with InfoPath because fields of an unsupported data type are marked as required, or because fields are corrupted. In SharePoint, try deleting the columns or editing the column properties to remove the required attribute.
-          ABC (Lookup)

The solution for this was I had to remove columns from the SharePoint list and then refreshed the InfoPath Form. Then deleted dropdown list control from Form and then again added it with binding to the Lookup list column. Publishing was successful.



Happy Learning! J


Show List of All Active Users inside Manage User Profiles

In SharePoint, Many of us might have wondered at some point about this question.

How to see list of all active users at once inside Manage User Profiles section in User Profile Service (UPS)?

This question might look silly but it is really a problem. “Manage User Profile” doesn’t show list of all active users. But it shows total number of profiles at the top (for ex. 15). Only when you type in any user name inside the “Find profiles” textbox and click on “Find” button, you will be able to see users matching with that name in the list.

 

So how to see all users in the list?

Not all active users at once, but yes definitely you can see list of all active users for a particular domain.

For this you have to just type the domain name inside the “Find profiles” textbox and click on “Find” button and then it will show all active users for that domain in the list below.

For ex: If UPS is having users synced from 2 different domains such as “domain1” and “domain2”. Then to see all users of “domain1”, just type “domain1” or “domain1\” in the Find profiles textbox(without quotes) and click on “Find” button. It will show you all those active users for that domain. Similarly you can see users for other domain.

This is true for SharePoint OnPremise. For Sharepoint Online, you can see all users like mentioned in this blog.



Happy Learning! J

Thursday, 3 September 2015

What is Central Administration, WFE and Application Server in SharePoint?


Central Administration (CA)
  • Central Administration is the management tool for your whole farm.
  • When you install and configure SharePoint Products and Features (SharePoint Foundation, or SharePoint Server etc.) on any application server, it automatically provisions a central administration site on that server.
  • Typically Central Administration is hosted on Application server. When the service “Central Administration” is running on any application server, that server hosts site for Central administration for the whole farm.
  • CA is kept on application server as it is not a high traffic site and won't affect performance of the application server.
  • It also allows you to extract a level of security by not putting it on a web front end, which could be accessed via a load balancer, instead it's on server that's behind the scenes that less users would even know about.
  • CA is an admin only site that has the potential to completely destroy your entire farm if misused or hacked. In many farms, particularly Internet/Extranet farms, the WFEs are exposed to the internet and are thus subject to being hacked. If CA isn't installed on a WFE, it eliminates the potential that a hacker will gain access to it.
  • On the server that is running SharePoint Products, click Start, point to Administrative Tools, and then click SharePoint Central Administration.
     
    Web Front End Servers (WFE server)
  •  A “Web Front End” (WFE) is a server where only “WSS/SharePoint Foundation Web Application” service is running from the below table “Server services”.
  • A WFE handles web requests from users and hosts all SharePoint files on the disk.
  • The assemblies are deployed to the global assembly cache (GAC) of every front-end web server in the farm and run with full trust.
  • A WFE has all the web applications (in IIS), Assembly in GAC and SharePoint related files in 12/14/15 hive.
  • You can have more than one WFE for load balancing (just install a secondary WFE in the Farm).

 Application Server (App server)
  •  An “Application Server” is a server that is capable of running any of the services from table below apart from the “WSS/SharePoint Foundation Web Application” service.
  • Application server hosts services such as: Excel, Search etc. and you can have one or more application servers in the farm for scalability and balancing.
  • You could split Excel and Search on two different servers (application) in the farm.
  • SharePoint will not replicate contents of WSP on app server as the “WSS/SharePoint Foundation Web Application” service is turned off there.

Server Services (MOSS version)

Server Service
Purpose 
Windows SharePoint Services Web Application (often referred to as 'Web Server' or 'WFE')
This service is responsible for serving the HTML to clients and routing requests to other services in the farm.
This service can exist on multiple servers. Those servers are called as WFE servers. 
Office SharePoint Server Search in Query Mode (often referred to as 'Query Server')
This service is responsible for executing search queries against a locally stored copy of the index
Yes, this role can exist on multiple servers.
Office SharePoint Server Search in Index Mode (often referred to as 'Index Server') 
This service is responsible for indexing all of the configured content sources, creating an index and propagating it to every Query server in the farm
Windows SharePoint Services Search
This service is basically a slimmed down version of the Office SharePoint Server Search service which combines both the Query and Index roles into a single service.
If you have more than one instance of this service in a farm, it will simply do the same thing as the other servers.
Excel Calculation Services
This service is responsible for performing calculations on Excel workbooks that are stored in the content databases.
Many instances of this service can exist on the same farm.
Document Conversions Load Balancer Service 
This service balances document conversion requests from across the server farm.
An application server can only have a single Document Conversions Load Balancer Service enabled.
Document Conversions Launcher Service 
This service schedules and initiates the document conversions on a server.
Multiple launchers can exist in the same farm.
Windows SharePoint Services Incoming E-Mail
This service is responsible for receiving incoming emails and placing them in email enabled lists. 
This service can run on multiple servers
Windows SharePoint Services Outgoing E-Mail 
This is not technically a SharePoint service but refers to an SMTP server which SharePoint send outbound email to
Central Administration
This service enables the central administration interface that is required for farm-wide administration.
This service can only run on one server in the farm i,e. on any single Application server. 



How Solution (.wsp) is deployed to SharePoint farm?

  • WSP Solution can be deployed with PowerShell script using commands Add-SPSolution and Install-SPSolution.
  • Add-SPSolution will move your solution to SP Admin database.
  • Install-SPSolution will create a timer job on all WFE’s to push all files to 12/14/15 hive, DLL's to GAC, Web.Config changes etc. to the Front end servers where you have "SP Web Application" service running.
  • It doesn’t matter which server you are using to deploy your WSP with PowerShell. It can be Application server or WFE server.
  • The solution functionalities will be always executed on your front end server, your app server doesn’t need the WSP artifacts.