Tuesday, December 19, 2017

How to overcome SharePoint's 5000 item limit threshold?

The best answer to this question is given on this blog, with an awesome analogy -

Courtesy -

https://sharepointmaven.com/how-to-overcome-sharepoint-5000-item-limit-threshold/

There is no more explanation beyond this blog..!!

Monday, December 18, 2017

RequestDigest value in SharePoint and it's Importance

 RequestDigest as a key through which,
  • You can GET information without using it.
  • There is some information you cannot GET without using it.
  • You need the key to PUT (POST) information in SharePoint.
When executing non-GET REST requests to the SharePoint API, you must add a valid request digest to your request. This digest proves validity of your request to SharePoint. Because this token is valid only for a limited period of time, you have to ensure that the token you have is valid, before adding it to your request or the request will fail. 

SharePoint includes a request digest token on the page in a hidden field named __REQUESTDIGEST

One of the most common approaches to work with the request digest, is to obtain it from that field and add it to the request, for example

var digest = $('#__REQUESTDIGEST').val(); $.ajax({ url: '/_api/web/...' method: "POST", headers: { "Accept": "application/json; odata=nometadata", "X-RequestDigest": digest }, success: function (data) { // ... }, error: function (data, errorCode, errorMessage) { // ... } });

Such request would work initially, but if the user would have the page open for a longer period of time, the request digest on the page would expire and the request would fail with a 403 FORBIDDEN result. By default, a request digest token is valid for 30 minutes, so before using it, you have to ensure that it's still valid. In the past you had to do this manually, by comparing the timestamp from the request digest with the current time. SharePoint Framework simplifies this process by offering you two ways of ensuring that your request has a valid request digest token.

1) Use the SPHttpClient to communicate with the SharePoint REST API

2) Retrieve valid request digest using the DigestCache service
If you can't use the SPHttpClient for communicating with the SharePoint REST API, you can obtain a valid request digest token using the DigestCache service provided with the SharePoint Framework. The benefit of using the DigestCache service over manually obtaining a valid request digest token is, that the DigestCache automatically checks if the previously retrieved request digest is still valid or not. If it's expired, the DigestCache service will automatically request a new request digest token from SharePoint and store it from subsequent requests. Using the DigestCache simplifies your code and makes your solution more robust.
To use the DigestCache service in your code, first import the DigestCache and IDigestCache types from the @microsoft/sp-http package:
Next, whenever you need a valid request digest token, retrieve a reference to the DigestCache service and call its fetchDigest method:

JavaScript Display Templates

There are 2 ways to include "JavaScript files" in SharePoint forms, web parts, lists, views -

1) Inclcude .js files in "Site Assets Library" or "Script Library".
2) Upload .js file in Master Page Gallery under "JavaScript Display Template Content Type".

Discussing more about "Javascript Display Template" -

There are 2 ways to include "JavaScript files" in SharePoint forms, web parts, lists, views -

1) Inclcude .js files in "Site Assets Library" or "Script Library".
2) Upload .js file in Master Page Gallery under "JavaScript Display Template Content Type".



JavaScript Display Template Content Type has some special Site Columns added to it that will help specify the target element (view,web-part etc..) 

Lets Look at the Steps to upload a new Js file as a new Javascript Display Template and look at the description of Site Columns.

1. Navigate to the Master Page Gallery (Site Settings -> under Web Designer Galleries -> Master Pages).

2. Select Files tab and then Upload Document.

3. Browse to the new JavaScript file that you have created and select Ok.





4. Choose Content Type as "JavaScript Display Template",
Target Control Type – By description “Target Control Type is the Type of Control that you will be using in this Display Template or JavaScript File”. For example if your Display Template or JavaScript File will be controlling the rendering of a View in a List, then the Target Control Type value should be “View”.
There are three possible options
  • Form
  • View
  • Field
Standalone – Specifies if you need to include this JavaScript File Override during view selection.Default options are
  • Override
  • Standalone
Target Scope – URL of the website this override applies to. This can be a relative path to your Site Collection or subsite.
Target List Template ID – Specify the ID of the list Template type this Override or JavaScript render applies to.
Lastly, "Publish a major version" of the js file uploaded in the master page gallery. 
Template ID List :-
  • 100   Generic list
  • 101   Document library
  • 102   Survey
  • 103   Links list
  • 104   Announcements list
  • 105   Contacts list
  • 106   Events list
  • 107   Tasks list
  • 108   Discussion board
  • 109   Picture library
  • 110   Data sources
  • 111   Site template gallery
  • 112   User Information list
  • 113   Web Part gallery
  • 114   List template gallery
  • 115   XML Form library
  • 116   Master pages gallery
  • 117   No-Code Workflows
  • 118   Custom Workflow Process
  • 119   Wiki Page library
  • 120   Custom grid for a list
  • 130   Data Connection library
  • 140   Workflow History
  • 150   Gantt Tasks list
  • 200   Meeting Series list
  • 201   Meeting Agenda list
  • 202   Meeting Attendees list
  • 204   Meeting Decisions list
  • 207   Meeting Objectives list
  • 210   Meeting text box
  • 211   Meeting Things To Bring list
  • 212   Meeting Workspace Pages list
  • 301   Blog Posts list
  • 302   Blog Comments list
  • 303   Blog Categories list
  • 1100   Issue tracking
  • 1200   Administrator tasks list
5. Since the File was upload in Master Page Gallery and we are using it in the same Site collection (not Subsite) the JS Link reference will be
~site/_catalogs/masterpage/JSLink.js
If the file was to be used in a Subsite you can use ~sitecollection URL token Instead.

Clearing Person/Group Values

To clear out or empty the values in person or group columns, how you do it depends on if the column is single-value or multi-value. For ...