4

I am trying to make an html page in an app, and I want to be able to get: SP.Utilities and _spPageContextInfo, which scripts do I need to add to my html in order to make it work?

I am in Office 365. I've tried the following scripts, but nothing worked:

<script type="text/javascript" src="/layouts/15/MicrosoftAjax.js"></script>

<script src="/_layouts/15/core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.debug.js"></script>
<script type="text/javascript" src="/_layouts/15/init.js"></script>  
<script type="text/javascript" src="/_layouts/15/SP.Core.js" ></script>
<script type="text/javascript" src="/_layouts/15/SP.Debug.js" ></script>
<script type="text/javascript" src="/_layouts/15/SP.Runtime.Debug.js></script>

anyone tried it?

3

_spPageContextInfo:

_spPageContextInfo have some useful values that added to SharePoint master page. But SharePoint apps built to be isolated and light.

You can’t access _spPageContextInfo form App pages, but you can access same values by different ways:

  1. URL strings and tokens in apps for SharePoint: http://msdn.microsoft.com/en-us/library/jj163816.aspx
  2. If then you need more values than not provided by tokens you can access what you want by load SP.ClientContext

Example: If you want to get the webServerRelativeUrl of the site on which you have installed your app, then simply

hostweburl = decodeURIComponent(getQueryStringParameter('HostUrl'));

Note: You don't need to add any JS files, you get this from query string

Refer _spPageContextInfo is not defined for more details.

SP.Utilities:

The SP.Utilities can be referred directly from code. For example if you want to send an email, the below snippet is used in the function.

appweburl + "/_api/SP.Utilities.Utility.SendEmail"; 
  • thank you. but how do I load SP.ClientContext? which scripts are necessary for it? – David Hemsey Dec 22 '15 at 13:26
  • 1
    @DavidHemsey Info on SP.ClientContext. Once you have a ClientContext object, you can get the current web and its server relative url. You won't need _spPageContextInfo. – wjervis Dec 22 '15 at 13:31
  • 1
    thank you guys, but. Again guys, what are the scripts required to get client context, as stated in my question it's not working for me. What scripts should I use to get client content, we can forget about spPageContextInfo now.. – David Hemsey Dec 22 '15 at 13:34
  • 1
    @DavidHemsey You get the web server relative url, from the query string. See the updated answer. – Asad Refai Dec 22 '15 at 13:44
  • 1
    getQueryStringParameter is declared in some MSDN examples (and everyone copy/pastes those), Not necessary as multiple SP libraries provide the same functionality: sharepoint.stackexchange.com/questions/159289/… – Danny '365CSI' Engelman Dec 22 '15 at 13:59
0
  • Load a regular SP page with a ListView
  • Open F12 developer tools
  • Type the name of the function, without ()
  • click the function definition

F12 source panel will open with the file the function is defined in

  • 1
    _spPageContextInfo doesn't appear to be a function. – David Hemsey Dec 22 '15 at 13:19
  • it is an object, not a function. Open all sources you think they are used in, then use Ctrf- search in the Sources panel – Danny '365CSI' Engelman Dec 22 '15 at 13:21
  • I didn't understand.. what should I do to make it available? – David Hemsey Dec 22 '15 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.