ECMAScript: SP.ClientContext is undefined or null

Sometime We cannot use SP.ClientContext in Site pages, Web part pages or Application pages. Although We was following this guide from msdn

Setting Up an Application Page for ECMAScript

If so, please replace the below lines

<script type=”text/ecmascript” src=”/_layouts/SP.Core.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Debug.js” />
<script type=”text/ecmascript” src=”/_layouts/SP.Runtime.Debug.js” />


<SharePoint:ScriptLink ID=”ScriptLink1″ Name=”sp.debug.js” LoadAfterUI=”true” Localizable=”false” runat=”server” />

Reference MSDN

This Post Has 0 Comments

  1. hrhenrikandersen

    When using SharePoint online i found this code to work.

    var clientContext;


    function initialize() {

    this.clientContext = SP.ClientContext.get_current();


    The strange part is that it works on some websites without the above code. Can anyone explain this?

  2. Jerry Cote

    Thank you – this worked perfectly!

Leave a Reply