SharePoint provides the JavaScript API reference files that contains the information used to access the data and build the custom applications. From the number of files, SP.JS is the most important file in the JSOM that provides the types and members the same as the Microsoft.SharePoint namespace to work with top-level sites, sub-sites and their lists and libraries.
The SP.JS file has the ClientContext object used for representing the context of SharePoint Objects and operations.
Here I will list each property of SP.ClientContext with an example.
SP.ClientContext.applicationName
Represent the name of the runtime application, where the current client application is located.
The following example gets the name of the application that runs in the current location.
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- appname = clientContext.get_applicationName();
- console.log("Application Name: "+ appname );
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Returns the default value
Application Name: JavaScript Library
The following example sets the name for the runtime application, where the current client application is located. The parameter represents the name of the runtime application.
The string length for the application name should be between 1 and 265 characters.
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- clientContext.set_applicationName(“My Application”);
- appname = clientContext.get_applicationName();
- console.log("Application Name: "+ appname );
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Application Name: My Application
SP.ClientContext.current
- Returns the current client context of the Client-Side Object Model (CSOM) runtime
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- }
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Gets or sets a Boolean value that indicates whether form digest handling is enabled. The following example retrieves the value for the current client context form digest settings is enabled or not.
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- console.log("Form Digest Handling Enabled: " + clientContext.get_formDigestHandlingEnabled());
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- clientContext.set_formDigestHandlingEnabled(true);
- console.log("Form Digest Handling Enabled: " + clientContext.get_formDigestHandlingEnabled());
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Form Digest Handling Enabled: true
SP.ClientContext.hasPendingRequest
Returns a Boolean value indicates whether the client runtime context has any pending request. The following example identifies the pending request.
- var clientContext = null;
- var oWeb = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- oWeb = clientContext.get_web();
- clientContext.load(oWeb);
- //Below code returns true, because the code awaiting to send the request
- console.log("Has Pending Request (Before Execution): "+ clientContext.get_hasPendingRequest());
- clientContext.executeQueryAsync(onSucceeded, onFailed);
- //Below code returns false
- console.log("Has Pending Request (After Execution): "+ clientContext.get_hasPendingRequest());
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Has Pending Request (Before Execution): true
Has Pending Request (After Execution): false
SP.ClientContext.requestTimeout
Gets or sets the timeout value for the current client context runtime. The following example code returns the default timeout value.
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- //Returns the default timeout value 180000 milliseconds
- console.log("Request Timeout Value: "+ clientContext.get_requestTimeout());
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);
Request Timeout Value: 180000
The following example code sets the timeout value to “20000” milliseconds for the current client context runtime. The parameter value should be greater than or equal to 0. 0 represents the no timeout for the current application.
- var clientContext = null;
- function contextInfo()
- {
- //Create an instance of the Current Context
- clientContext = SP.ClientContext.get_current();
- clientContext.set_requestTimeout(20000);
- //Returns the default timeout value 20000 milliseconds
- console.log("Request Timeout Value: "+ clientContext.get_requestTimeout());
- }
- //Make sure the SharePoint script file 'sp.js' is loaded before the function 'contextInfo' runs
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', contextInfo);

SriramPosted Jul 6, 2015, 1:26 AM
Exce;;ent............
Karthik Muthu KaruppanPosted Apr 23, 2015, 11:19 AM
good one
Rahul Kumar SaxenaPosted Apr 22, 2015, 2:30 PM
Good Show.
Krishnanand SivarajPosted Apr 22, 2015, 7:12 AM
good one shantha
Shantha Kumar TPosted Apr 22, 2015, 1:11 AM
Thanks Gowtham
Shantha Kumar TPosted Apr 22, 2015, 1:11 AM
Thanks Santhakumar
Gowtham RajamanickamPosted Apr 21, 2015, 11:26 PM
good one shantha
Santhakumar MunuswamyPosted Apr 21, 2015, 10:54 PM
Thanks for nice article