sp.clientcontext is not a constructor

Discussion in 'Code' started by securityhope, Feb 20, 2017.

  1. securityhope

    securityhope Administrator Staff Member

    Joined:
    Aug 3, 2016
    Messages:
    1,241
    Likes Received:
    0
    Trophy Points:
    36
    You need to get the context after SP.js load like below

    Code:
    SP.SOD.executeFunc('SP.js','SP.ClientContext',function(){var_ctx=SP.ClientContext.get_current();});
    Initializes a new instance of theClientContextobject for the specified SharePoint site.

    Last modified:June 25, 2013

    Applies to:apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

    Code:
    varobject =newSP.ClientContext(serverRelativeUrlOrFullUrl)


    SP.ClientContext

    A new instance of the client context for the specified SharePoint site.

    The following example gets the client context for the specified URL.


    Code:
    varurl ='replace with server-relative or absolute URL';varclientContext;varwebsite;// Make sure the SharePoint script file 'sp.js' is loaded before your// code runs.SP.SOD.executeFunc('sp.js','SP.ClientContext', sharePointReady);// Create an instance of the client context for the specified URL.functionsharePointReady() {    clientContext =newSP.ClientContext(url);    website = clientContext.get_web();    clientContext.load(website);    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);}functiononRequestSucceeded() {    alert('URL of the website: '+ website.get_url());}functiononRequestFailed(sender, args) {    alert('Error: '+ args.get_message());}
    

    sp.clientcontext is undefined sharepoint 2013

    A better way to use the Script On Demand is this

    Code:
    if(!SP.SOD.executeOrDelayUntilScriptLoaded(myFunction,'sp.js')){LoadSodByKey('sp.js');};

    Searches related to sp.clientcontext is not a constructor

    • sp.clientcontext sharepoint 2010
    • sp.clientcontext.get_current() sharepoint 2013
    • sp.filecreationinformation sharepoint 2010
    • sp.clientcontext(siteurl) not working
    • uncaught typeerror: sp.requestexecutor is not a constructor
    • sp.clientcontext.get_current() not working
    • new sp clientcontext is not a constructor
     

Share This Page

Share