Archive for August, 2014

Introduction

Have you ever tried using SP.UI.ModalDialog.showModalDialog(options) in SharePoint 2013? I discovered a strange behaviour.

After migrating my code from SharePoint 2010 to SharePoint 2013 the calls to showModalDialog failed with the message that the method cannot be found (JavaScript). When checking it in IE Developer Tools this isn’t surprising at all. The required js-file isn’t loaded.

But why? I guess it must be the new Script on Demand (SOD) Model that was introduced in SharePoint 2013.

SharePoint 2010 Example

  1. function ShowServerInformation() {
  2. var options = {
  3. url: ‘/_layouts/Management/GeneralInformation.aspx’,
  4. tite: ‘Management Information’,
  5. allowMaximize: false,
  6. showClose: true,
  7. width: 430,
  8. height: 230
  9. };
  10. SP.UI.ModalDialog.showModalDialog(options);
  11. return false;
  12. }

It’s very easy to fix this problem.

Remove the Java Script reference.

 

  1. <script src=”/_layouts/sp.js” type=”text/javascript”></script>
  2. <script src=”/_layouts/SP.UI.Dialog.js” type=”text/javascript”></script>
  3. Add to the url variable “?IsDlg=1″`
  4. Replace the command SP.UI.ModalDialog.showModalDialog() with the new command
  5. SP.SOD.execute(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, options);

After this few changes your solution will work correctly.

SharePoint 2013 Example

  1. function ShowServerInformation(featureId) {
  2.  var options = {
  3.   url: ‘/_layouts/Management/GeneralInformation.aspx?IsDlg=1’,
  4.           tite: ‘Management Information’,
  5.            allowMaximize: false,
  6.             showClose: true,
  7.             width: 430,
  8.              height: 230
  9.        }

Notice

I first tried the “executeOrDelayUntilScriptLoaded” function, but it was not much help. It just “swallowed” my function call but never executed it because the js-file I specified was never loaded.

Advertisements

How to enable Rating in SharePoint?

It’s very straight forward to enable rating in SharePoint lists and libraries.

If you wish to utilize Ratings on a SharePoint list or library, you might think that you can do so by simply adding the “Rating (0-5)” site column to your existing list, library or content type.

In fact, SharePoint will allow you to do that, however doing so may or may not provide the intended results. As you may already know, the proper way to enable ratings is from the list’s settings page.

  • Once created, open the list select “List Tools” Tab -> List Tab -> List Settings
  • Under General Settings click on the “Ratings settings” link

Rating in SharePoint

  • Under the Rating Settings section select “Yes” for “Allow items in this list to be rated?”

Allow items

  • Now a new field “Rating (0-5)” is added to the list. But the actual field name is “AverageRating”.
  • Add some items in the list.

AverageRating

  • When hovering the mouse over the Rating field it’ll show a message to add a rating. You can select the rating as relevant.

Knowing that the Rating feature relies on the User Profile Service, I checked in Central Admin under “Manage Services on Server” and verified that this service was running. I found an article that mentioned a specific timer job called “User ProfileService Application – Social Rating Synchronization Job” that is required for ratings to work. So I checked my Timer Job Definitions and could not find this Timer job. While this timer job is not specifically necessary for the ratings stars to turn yellow, I took this as a hint that something was not quite right with the rating feature.

Average Rating 2This job executes every hour by default. If required it can be executed manually by “Central Administration -> Monitoring -> Timer Jobs -> Review Job Definitions -> User Profile Service Application – Social Rating Synchronization Job -> Run Now” or change the “Recurring Schedule” as required.

AverageRating 3

Once the Synchronization job has executed then users can see the average ratings (Blue Stars).

Before Synchronization Job execution:

AverageRating
After Synchronization Job execution:

After Synchronization Job execution

Hover the mouse over the blue star ratings to know you’re rating (only if you have already given a rating).

Introduction

This Presence helps users to get in touch with their colleagues easily. A user can see more information about colleagues, like contact numbers, designation, departments without going to their personal page. Also it indicates the presence of a colleague whether he/she is available, away or offline.

Presentation

The presence awareness of SharePoint depends on a couple of different pieces of technology, all working together, namely:

  • SharePoint
  • Exchange
  • Lync
  • Active Directory

This is a very easy and straight-forward requirement for single users. What if you need to provide a presence indicator of more than one user? In thay case you need to be careful with some parameters in the code above. These are:

  • The “id“must be unique and format must be like: “id=”imn_716,type=sip””.
  • Provide an “alt” attribute value to the image.
  • Provide a “src” attribute to the image.
  • And of course be careful with the classes.

User Presence with Picture

Now in this article we will see how to display the OC or Lync Presence of a user on mouse hover on the picture of the user. In one of my articles we saw how to get my followers and of those I am following. In this article let’s display users to whom I am following. You can use these snippets in Custom Web parts or Content Editor Web parts to show the respective user presence status.

Lync Presence: DefaultRender
  1.    <span>
  2.  <span class=‘ms-imnSpan’>
  3.   <a href=‘#’ onclick=‘IMNImageOnClick(event);return false;’ class=‘ms-imnlink ms-spimn-presenceLink’ >
  4.    <span class=‘ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10×10’>
  5.     <img name=‘imnmark’ title= ShowOfflinePawn=‘1’ class=‘ms-spimn-img ms-spimn-presence-disconnected-10x10x32’ src=    ‘/_layouts/15/images/spimn.png?rev=23’ alt=‘User Presence’ sip=‘test@hotmail.com’ id=‘imn_1,ty    pe=sip’ />
  6.    </span>
  7.   </a>
  8.  </span>
  9. <span>
  10.  <a href=‘#’ onclick=‘IMNImageOnClick(event);return false;’ class=‘ms-imnlink’ tabIndex=‘-1’>
  11. <img name=‘imnmark’ title= ShowOfflinePawn=‘1’ class=‘ ms-hide’ src=‘/_layouts/15/images/spimn.png?rev=23’ alt=‘Us  er Presence’ sip=‘parth@live.com’ id=‘imn_2,type=sip’ /></a>Parth P
  12. </span>
  13. </span>
  • Lync Presence: WithPictureDetailView
  1. <div>
  2. <div class=“ms-tableRow”>
  3.  <div>
  4.   <span class=‘ms-imnSpan’>
  5.   <a href=‘#’ onclick=‘IMNImageOnClick(event);return false;’ class=‘ms-imnlink ms-spimn-presenceLink’ >
  6.    <span class=‘ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10×10’><img name=‘imnmark’ title= ShowOfflinePaw   n=‘1’ class=‘ms-spimn-img ms-spimn-presence-disconnected-10x10x32’ src=‘/_layouts/15/images/spimn.png?rev=23’ alt=‘   User Presence’ sip=‘Parth@live.com’ id=‘imn_661,type=sip’ /></span>
  7.   </a>
  8.   </span></span>
  9. </div>
  10. <div class=“ms-tableCell ms-verticalAlignTop”>
  11. <div class=“ms-peopleux-userImgDiv”><span class=“ms-imnSpan”><a href=‘#’ onclick=‘IMNImageOnClick(event);return false;’ class=‘ms-imnlink’ tabIndex=‘-1’><img name=‘imnmark’ title= ShowOfflinePawn=‘1’ class=‘ ms-hide’ src=‘/_layouts/15/images/spimn.png?rev=23’ alt=‘User Presence’ sip=‘test@hotmail.com’ id=‘imn_3452,type=sip’ /></a><span><img style=“width:62px; height:62px; border:none” src=http://www.bing.com&#8221; alt=” Ram” /></span></span></span></div></div><div class=“ms-tableCell ms-peopleux-userdetails ms-noList”><ul style=“max-width:150px”><li><div class=“ms-noWrap”><span><a href=‘#’ onclick=‘IMNImageOnClick(event);return false;’ class=‘ms-imnlink’ tabIndex=‘-1’><img name=‘imnmark’ title= ShowOfflinePawn=‘1’ class=‘ ms-hide’ src=‘/_layouts/15/images/spimn.png?rev=23’ alt=‘User Presence’ sip=‘test@hotmail.com’ id=‘imn_34523,type=sip’ /></a> Parth P</span></div></li></ul></div>
  12. </div>
  13. </div>

Use the following procedure to create a sample.

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select “Site Actions” | “Edit Page”.

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”.

Step 3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:
  1. <script type=“text/javascript”>
  2.         function showPresencePeople(followed) {
  3.             var htmlStr = “”;
  4.             ClientContext context = new Microsoft.SharePoint.Client.ClientContext(“http://SPSite”);
  5.             GroupCollection groupCollection = context.Web.SiteGroups;
  6.             context.Load(groupCollection,
  7.             groups = > groups.Include(
  8.             group = > group.Users));
  9.             context.ExecuteQuery();
  10.             foreach (Group group in groupCollection)
  11.             {
  12.             UserCollection userCollection = group.Users;
  13.             foreach (User userObj in userCollection)
  14.             {
  15.             var userName = userObj.get_name();
  16.             var userSiteUri = userObj.get_personalSiteUri();
  17.             var userId = userObj.get_id();
  18.             var userPictureUri = userObj.get_imageUri();
  19.             var userEmailAddress = userObj.get_emailAddress();
  20.             if (userPictureUri == null) {
  21.                 var picsStr = ‘<span class=”ms-imnSpan”><a href=”#” onclick=”IMNImageOnClick(event);return false;” class=”ms-imnlink ms-spimn-prese  nceLink” ><span class=”ms-spimn-presenceWrapper ms-spimn-imgSize-8×72″><img onload=”IMNRC(\’‘ + userEmailAddress + ‘\’)” name=“imnmark” title=“‘ + userName + ‘” ShowOfflinePawn=  “1” class=“ms-spimn-img ms-spimn-presence-disconnected-8x72x32” src=“/_layouts/15/images/spimn.png?rev=23” alt=“‘ + userName + ‘” sip=“‘ + userEmailAddress + ‘” id=“imn_’ + i + ‘,type=sip” /></span></a></span></span><span class=“ms-imnSpan”><a href=“#” onclick=“IMNImageOnClick(event);return false;” class=“ms-imnlink” tabIndex=“-1”><img onload=“IMNRC(\” + userEmailAddress + ‘\’)” name=“imnmark” title=“T_’ + userName + ‘” ShowOfflinePawn=“1” class=” ms-hide” src=“/_layouts/15/images/spimn.png?rev=23” alt=“A’ + userName + ‘” sip=“‘ + userEmailAddress + ‘” id=“simn_’ + i + ‘,type=sip” /></a><span class=“ms-peopleux-imgUserLink”><span class=“ms-peopleux-userImgWrapper” style=“width:72px; height:72px”><a href=“‘ + userSiteUri + ‘”><img style=“min-width:72px; min-height:72px; clip:rect(0px, 72px, 72px, 0px); max-width:72px” src=“/_layouts/15/images/PersonPlaceholder.200x150x32.png” alt=“‘ + userName + ‘” /></a></span></span></span>‘;
  22.             }
  23.             else {
  24.                 var picsStr = ‘<span class=”ms-imnSpan”><a href=”#” onclick=”IMNImageOnClick(event);return false;” class=”ms-imnlink ms-spimn-prese  nceLink” ><span class=”ms-spimn-presenceWrapper ms-spimn-imgSize-8×72″><img onload=”IMNRC(\’‘ + userEmailAddress + ‘\’)” name=“imnmark” title=“‘ + userName + ‘” ShowOfflinePawn=  “1” class=“ms-spimn-img ms-spimn-presence-disconnected-8x72x32” src=“/_layouts/15/images/spimn.png?rev=23” alt=“‘ + userName + ‘” sip=“‘ + userEmailAddress + ‘” id=“imn_’ + i + ‘,type=sip” /></span></a></span></span><span class=“ms-imnSpan”><a href=“#” onclick=“IMNImageOnClick(event);return false;” class=“ms-imnlink” tabIndex=“-1”><img onload=“IMNRC(\” + userEmailAddress + ‘\’)” name=“imnmark” title=“T_’ + userName + ‘” ShowOfflinePawn=“1” class=” ms-hide” src=“/_layouts/15/images/spimn.png?rev=23” alt=“A’ + userName + ‘” sip=“‘ + userEmailAddress + ‘” id=“simn_’ + i + ‘,type=sip” /></a><span class=“ms-peopleux-imgUserLink”><span class=“ms-peopleux-userImgWrapper” style=“width:72px; height:72px”><a href=“‘ + userSiteUri + ‘”><img style=“min-width:72px; min-height:72px; clip:rect(0px, 72px, 72px, 0px); max-width:72px” src=“‘ + userPictureUri + ‘” alt=“‘ + userName + ‘” /></a></span></span></span>‘;
  25.             }
  26.             htmlStr += picsStr;
  27.         }
  28.             }
  29.             $(‘#followedDiv’).html(htmlStr);
  30.         }
  31. </script>
  32. <div id=” followedDiv'”></div>

In this code, the values of attributes, like sip, alt and src are given properly and are mandatory.

Here the userEmailAddress variable stores the email address of the user, the userPictureUri stores the URL of the user picture, the userName stores the name of the user and userSiteUri is the URL of the My Site page URL.

If you are rendering a presence for multiple/single users using the preceding snippets, ensure you:

  • Set the email id, image source and alt property accordingly
  • Id property always has unique value
  • Opening and closing tags are managed properly.

The Output of the Presence Indicator with Picture is as in the following:

Presence Indicator.jpg
Important: when you are using JavaScript to generate this HTML and then bind it to the control as in the example above, do not forget to call “IMNRC“ on the “onload” of the image where the presence is displayed. Without this “IMNRC” call the user presence indicator will not work.

Message in SharePoint Designer 2013: The option for the SharePoint 2013 Workflow Platform is not available because the workflow service is not configured on the server.

Introduction

This article explores how to configure a workflow infrastructure 2013. I installed SharePoint Designer 2013 and tried to create a SharePoint 2013 workflow but there was no option to select the platform type as “SharePoint 2013 Workflow” and I was getting the following message in SharePoint Designer 2013:

SharePoint 2013 Workflow

Here is the procedure:

1. Make sure the Workflow Manager 1.0 for SharePoint 2013 server is installed and configured properly. If the workflow manager 1.0 is not installed then use the following URL:

2. Verify that all the following services are running (to check the service status, press the Windows key+R and type services.msc):

  • Workflow Manager Backend
  • Windows Fabric Host Service
  • Service Bus Gateway

3. Open “SharePoint 2013 Management Shell” and run the following command:

Enable-SPFeature -Identity WorkflowServiceStore –Url $yourUrl

Replace $yourUrl with your site collection URL.

In my case, I was getting a message saying that the feature was already activated at that site.

4. Open IIS, verify that “Workflow Management Site” is working fine.

You can determine which ports SharePoint Server 2013 and Workflow Manager are using for both HTTP and HTTPS by using IIS Manager as shown in the following figure.

Workflow Management Site

5. You need to register the workflow service with an existing site collection using the following Register-SPWorkflowService cmdlet. Execute it in the SharePoint 2013 Management Shell. Please ensure you use the following syntax:

Register-SPWorkflowService –SPSite “http://svr7007/” –WorkflowHostUri “https://svr7007:12290″ –AllowOAuthHttp

Change the port number if you want to use HTTP (12291) or HTTPS (12290) to communicate between the Workflow Manager and SharePoint Server 2013.

6. Finally, open SharePoint Designer 2013 and check that you can create a SharePoint 2013 workflow.

SharePoint 2013 Workflow1

Introduction

There are several ways to enable the Developer Dashboard in SharePoint 2010 and 2013. I always prefer the PowerShell method, but for the sake of completeness I will show several options here.

Notice that there are the following options for the Developer Dashboard:

  •  On

SharePoint 2010: The Developer Dashboard will always be rendered at the bottom of each page.

SharePoint 2013: The Developer Dashboard icon will always be displayed at the top right corner. It will not be appended to each page.

  • Off

SharePoint 2010 & 2013: The Developer Dashboard will not be available.

  •  OnDemand

SharePoint 2010: The Developer Dashboard will only be appended to a page after clicking on the icon in the ribbon.

SharePoint 2013: This mode is not available in 2013 since it reflects the behavior of On now.

Enabling Developer Dashboard

using PowerShell

  1. $devdashboard =[Microsoft.SharePoint.Administration.SPWebService]::ContentService.
    DeveloperDashboardSettings;
  2. $devdashboard.DisplayLevel = ‘OnDemand’;
  3. $devdashboard.Update()
  4. Write-Host (“Developer Dashboard Level: “ + $contentService.DeveloperDashboardSettings.DisplayLevel)

Program code

  1. Enabling Developer Dashboard using Object Model
  2. SPWebService service = SPWebService.ContentService;
  3. service.DeveloperDashboardSettings.DisplayLevel=Microsoft.SharePoint.Administration.
    SPDeveloperDashboardLevel.OnDemand;
  4. service.Update();

Using STSADM

  1. STSADM.exe -o setproperty -pn
  2. developer-dashboard -pv OnDemand

Conclusion

The Developer Dashboard can be disabled by setting the display level value to “Off”. As needed the display level can be set to “On”, “Off” or “OnDemand” in the code snippets above. This operation requires a Farm Administrator permission. Make sure you have farm admin access before enabling/disabling the developer dashboard.

Introduction

This article explains what the various options are that we need to avoid list throttling exceptions.

Once you understand that the throttle exists and can catch exceptions, you may want to override the throttle, using the object model. There are a couple of ways to do this.

There are the following 3 options for SPQueryThrottleOption:

  • Default: The normal behavior where all users who are not web server box administrators will be subject to the List View Threshold, including users with “Full Read” or “Full Control” permissions. This is the default behavior unless otherwise specified.
  • Override: If the user has “Full Control” or “Full Read” permissions, the List View Threshold for Auditors and Administrators will apply to this SPQuery and List View Lookup Threshold will not be applied. For more info on what the List View Lookup Threshold does, read this article.
  • Strict: List View threshold will apply for everyone, including web server box administrators. You can use this option to ensure that your code does not cause server stress even if it is being run as the box administrator on one of the web servers, since box administrators are not subject to the thresholds so may inadvertently slow down the servers.

The default list throttling limit in SharePoint 2013 is 5000.

To modify the default setting go to:

Central Administration > Manage Web Applications > General Settings > Resource Throttling > List View Threshold

If we change this option then it will have global affect and that is not the best way. So, we will determine what are the various options we need to set it from code.

Example: Consider an where list throshold error.

  1. try
  2. {
  3. using (SPSite site = new SPSite(SPContext.Current.Site.Url))
  4.                 {
  5.                     using (SPWeb web = site.OpenWeb())
  6.                     {
  7.                         SPList list = web.Lists.TryGetList(“PersonalInfo”);
  8.                         SPQuery query = new SPQuery();
  9.                         // Define columns to fetch
  10.                         query.ViewFields = “<FieldRef Name=\”Title\” /><FieldRef Name=\”Address\” />”;
  11.                         // Force to fetch only the specified columns
  12.                         query.ViewFieldsOnly = true;
  13.                         query.Query = “<Where><Contains><FieldRef Name=\”Address\” /><Value Type=\”Text\”>Pune</Value></Contains></Where>”;
  14.                         //Define the maximum number of results for each page (like a SELECT TOP)
  15.                         query.RowLimit = 10;
  16.                         // Query for items
  17.                         SPListItemCollection items = list.GetItems(query);
  18.                         foreach (SPListItem item in items)
  19.                         {
  20.                             Console.WriteLine(item[“Title”] + ” : “ + item[“Address”]);
  21.                         }
  22.                     }
  23.                 }
  24.  }
  25. catch (SPQueryThrottledException)
  26. {
  27. //Retrieving all items can trigger the throttle
  28. }

The preceding query will provide more results if the list is large. We will see the options for how to work on Throttling from the code.

  1. try
  2. {
  3. using (SPSite site = new SPSite(SPContext.Current.Site.Url))
  4.                 {
  5.                     using (SPWeb web = site.OpenWeb())
  6.                     {
  7.                         SPList list = web.Lists.TryGetList(“PersonalInfo”);
  8.                         SPQuery query = new SPQuery();
  9.                       query.QueryThrottleMode = SPQueryThrottleOption.Override;
  10.                         // Define columns to fetch
  11.                         query.ViewFields = “<FieldRef Name=\”Title\” /><FieldRef Name=\”Address\” />”;
  12.                         // Force to fetch only the specified columns
  13.                         query.ViewFieldsOnly = true;
  14.                         query.Query = “<Where><Contains><FieldRef Name=\”Address\” /><Value Type=\”Text\”>Pune</Value></Contains></Where>”;
  15.                         //Define the maximum number of results for each page (like a SELECT TOP)
  16.                         query.RowLimit = 10;
  17.                         // Query for items
  18.                         SPListItemCollection items = list.GetItems(query);
  19.                         foreach (SPListItem item in items)
  20.                         {
  21.                             Console.WriteLine(item[“Title”] + ” : “ + item[“Address”]);
  22.                         }
  23.                     }
  24.                 }
  25.  }
  26. catch (Exception ex)
  27. {
  28. }

Set the SPQuery.QueryThrottleMode property to SPQueryThrottleOption.Override to disable throttling for a specific query.

This is a good way to disable throttling.

Note: In order to avoid a list throttling exception, the preconditions for the “Object Model override” attribute must be “Yes” and the query should be executed under Super User.

Introduction

If you want to make your custom property searchable then you need to create a managed property for that custom property.

I have added a new property “Initials” to my User Profile Synchronization Service and mapped it to a property from AD. That works and the property is properly imported into the user’s profiles. I have even managed to successfully show it in search results; however I still can search for it specifically.

This managed property acts as a bridge between the search and custom properties.

Section: Configuring Managed Properties in Search Service on Server

Step 1

In SharePoint Search Service, select the “Search Schema” option.

Search Schema

Step 2

Select “New Managed Property”.

New Managed Property

Step 3

The following Managed Properties need to be created.

  1. Country
    • Property Name: Country
    • Type: Text
    • Searchable: Yes
    • Queryable: Yes
    • Retrievable: Yes
    • Allow Multiple Values: No
    • Refinable: Yes-active
    • Sortable: No
    • Safe: No
    • Alias: —
    • Token Normalization: Yes
    • Complete Matching: No
    • Include content from all crawled properties: Yes

Select “Add a Mapping”.

Mapping

Map

Select “All Categories” then search for “Country” then click “Ok”.
The property is mapped as given in the following screen shot:

Ok

Conclusion

This tracking has an impact on the relevancy of search results. For example, a search result that is often clicked by users will automatically be displayed higher up in the search results.