Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Archive for November, 2015

REST or JSOM – Scenario based Usage

Posted by Paul on November 20, 2015

In this article we can see the when to use REST and when to use JSOM depending on the scenario.

image

REST

REST is Representational State Transfer. REST is an architectural style and uses HTTP protocol. SharePoint 2013 onwards REST API is supported.

For filtering data, REST supports OData protocol.

One of the example of REST URL is given below:

http://server/_api/web/lists

You can find more REST examples from References.

JSOM

JSOM (JavaScript Object Model) is CSOM (Client Side Object Model) of interacting with SharePoint. This programming way is available from SharePoint 2010 onwards. JSOM Programming requires the following:

1. Deeper understanding of the SharePoint CSOM API

2. Reference to JSOM JavaScript files

3. CAML query used for filtering

Following is an example code for JSOM:

var listTitle = “Contacts”;

using(var context = new ClientContext(“http://url”))

{

var list = context.Web.Lists.GetByTitle(listTitle);

context.Load(list);

context.ExecuteQuery();

}

image

You can see References for source-code example.

REST Advantages

Following are the advantages of going with REST:

1. REST web requests are easier to work with that we can use Browser to test them

2. No overheads of WSDL creation Or Detailed SharePoint knowledge required

3. No overheads of tying up with Service Reference

4. Direct Calls for fetch, insert, update, delete, find operations

5. Better Interoperability supporting different clients on different platforms, programming models

In this way REST is more preferred among SharePoint Programmers.

JSOM Advantages

Following are the advantages of JSOM over REST which I would prefer to use only in particular scenarios.

1. JSOM supports Batching.

Batching is the technique of tying multiple queries and sending to server. In this way, the roundtrip can be reduced to one.

Scenario: You have a Web Page where 10 list items needs to be loaded. In the case of REST, this will require 10 roundtrips to the server. Right?

But if you are using JSOM, you can wrap all the queries into one roundtrip. Invoke the Load() method multiple times as shown below.

context.Load(list1);

context.Load(list2);

context.Load(list10);

Then we can call the ExecuteQuery() method which will actually send the query to the server. This is the advantage of Batching in JSOM.

image

image

Chattier is another term which means the Opposite of Batching. Chattier means it requires chat like request-response between client & server. So REST is chattier & JSOM not.

References

http://www.jeanpaulva.com/index.php/2015/01/10/sharepoint-rest/

http://www.c-sharpcorner.com/UploadFile/40e97e/jsom-batching-code-example/

Summary

In this article we can have explored the usage of REST vs. JSOM based on scenario.

Advertisements

Posted in SharePoint, SharePoint 2013 | Tagged: , | 1 Comment »

Sign In as Different User in SharePoint 2013

Posted by Paul on November 19, 2015

In this post I will take you through one common real-life scenario in SharePoint 2013.

Scenario

You are working on a SharePoint site. For testing a page, you need to Sign In as a different user. SharePoint only provides Sign Out menu item.

image

On clicking the Sign Out you will get signed out & the browser may prompt to close. Once reopening the browser you will be again signed in as the old user. Problem repeats!

How to Sign In as a different user?

Background

SharePoint 2010 had a menu item called Sign in as different user. But Microsoft removed it in SharePoint 2013 for various reasons.

Solution

Following are few solutions to apply for the current situation.

Solution 1: URL

You can explicitly use the Close Connection Url with the parameter.

_layouts/closeConnection.aspx?loginasanotheruser=true

For example if your Site URL is http://server/site

Your final URL will be:

http://server/site/_layouts/closeConnection.aspx?loginasanotheruser=true

On using the URL you will be prompted with the Sign In box.

image

Hope this will solve your problem.

Solution 2: IE Settings

Alternatively, you can go to the IE Settings to change the Login option as shown below.

Internet Options > Security (tab) > Custom Level (button) > Prompt for user name and password.

image

image

If your Administrator is managing the settings, you will not be able to change it.

Summary

In this post we have explored a common real life scenario in SharePoint 2013.

Posted in SharePoint, SharePoint 2013 | Tagged: , | Leave a Comment »

JSOM Batching Code Example

Posted by Paul on November 12, 2015

In this article we can explore a sample JSOM code which will reveal the Batching advantage of JSOM.

Batching

Batching is one core advantage of JSOM over REST API. Batching minimizes the roundtrips involved by grouping all the queries together.

For example, if you have 10 SharePoint lists to be queried from a page, REST API requires 10 roundtrips which would be taking around 20 seconds. Here we can use JSOM to combine the requests into 1 roundtrip there by reducing the time to 2 seconds. (90% time reduction)

image

Network Roundtrip occupies the majority time involved in a web page loading.

JSOM Example

In this example we are using 2 lists named Contacts A and Contacts B. Please create these lists from template Contacts & add one item in each.

image

image

Now create a new page & add a content editor web part. Insert following code into it. Change the server URL before saving.

http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js

var siteUrl = ‘http://server‘;

$(document).ready(function () {

    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, “sp.js”);

    }

)

function retrieveListItems() {

   var clientContext = new SP.ClientContext(siteUrl);

    var oList = clientContext.get_web().get_lists().getByTitle(‘Contacts A’);

    var camlQuery = new SP.CamlQuery();

    camlQuery.set_viewXml(” +

        ‘110’);

    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    var oList2 = clientContext.get_web().get_lists().getByTitle(‘Contacts B’);

    var camlQuery2 = new SP.CamlQuery();

    camlQuery.set_viewXml(” +

        ‘110’);

    this.collListItem2 = oList2.getItems(camlQuery2);

    clientContext.load(collListItem2);

  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));       

}

function onQuerySucceeded(sender, args) {

    var listItemInfo = ”;

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {

        var oListItem = listItemEnumerator.get_current();

        listItemInfo += ‘nID: ‘ + oListItem.get_id() +

            ‘nTitle: ‘ + oListItem.get_item(‘Title’);

    }

    alert(listItemInfo.toString());

    var listItemInfo2 = ”;

    var listItemEnumerator2 = collListItem2.getEnumerator();

    while (listItemEnumerator2.moveNext()) {

        var oListItem2 = listItemEnumerator2.get_current();

        listItemInfo2 += ‘nID: ‘ + oListItem2.get_id() +

            ‘nTitle: ‘ + oListItem2.get_item(‘Title’);

    }

    alert(listItemInfo2.toString());

}

function onQueryFailed(sender, args) {

    alert(‘Request failed. ‘ + args.get_message() + ‘n’ + args.get_stackTrace());

}

Testing the Code

Save and Refresh the page. You can see that the items from both lists are fetched.

image

image

You can see that the above message boxes shows items from 2 different lists. The code completed in one roundtrip instead of two.

image

REST is Chattier, but JSOM allows Batching.

References

https://msdn.microsoft.com/en-us/library/office/jj163201.aspx

Summary

In this article we have explored a JSOM batching example.

Posted in SharePoint, SharePoint 2013 | Tagged: , , , , | Leave a Comment »

SharePoint Non-Functional Requirements

Posted by Paul on November 5, 2015

In this article we can explore the typical Non-Functional Requirements in the SharePoint world.

You can download the template here.

image

Non-Functional Requirements

Non-Functional Requirements are additional to the Functional Requirements. Non-functional Requirements aka NFR contains the operational aspects of the application rather than the behavioral ones. Depending on your organization & processes:

· There can be separate documents for Functional & Non-Functional requirements

· Or, It can be the same document

image

Non-Functional Parameters

Following are the important Non-Functional Parameters:

1. Users

2. Capacity

3. Performance

4. Sensitivity

5. Scalability

6. User Interface

7. Availability

8. Recoverability

9. Security

10. Interoperability

Let us see each category questions in the following table. In the real-worlds scenario these questions need to be answered by the business team.

NFR Table

Item

Value

Example

Users

Total Number of Users

1000

Total Number of Concurrent Users

100

User Locations

US, UK, Singapore

Peak Hours / Period

10 AM EST

Performance

Response Time for Home Pages

3 seconds

Response Time for Operational Pages

5 seconds

Response Time for Reporting Pages

10 seconds

Capacity

Average Size of Documents

300 KB

Total Size of Database on Day-1

1 GB (SP have 200 GB limit)

Total Size of Database after Year-1

2 GB

Maximum Number of List items

2000 (SP have limit of 5000)

Sensitivity

Sensitive Data Involved

If Yes, On-Premise deployment would be preferred so that data would not go outside.

Legal, Privacy, Copyrighted components/data involved

Scalability

Expected Growth % in Users per Year

20%

Expected Growth % in Database Size per Year

20%

User Interface

Languages Supported

English Only

Devices Accessed

Mobile, Tablet, Desktop

Responsive Design Required

Corporate Branding Required

Yes

Supported Browsers

IE 11, Chrome

Supported Operating Systems

Windows 7, 8, Android

Security

User Roles – Activities

Administrators – Manager Users

Contributors – Create Content

Approvers – Approve / Reject

Viewers – Read Content

Interoperability

Depending Applications

Read/Write by HR

Dependent Applications

Read/Write from Sales

Availability

Availability %

99%

Recoverability

Restoration Period

12 hours

image

You may need to cross-check the NFR with SharePoint Boundary Limitations given in References.

For example:

· The recommended max-size for site collection is 200 GB

· The default max-number of list items is 5000

References

https://technet.microsoft.com/en-us/library/cc262787.aspx

Summary

In this article we have explored the typical Non-Functional Requirements for a SharePoint project. The template document is attached with this article.

Posted in SharePoint, SharePoint 2013 | Tagged: , | Leave a Comment »