Forum Discussion

Nigel_Price9911's avatar
Nigel_Price9911
Iron Contributor
Feb 08, 2018
Solved

_spPageContextInfo is undefined

I have a very simple REST call to get all of the items in a list(Announcements) but when I run this Mikael's script editor web part I get this error _spPageContextInfo' is not defined. where _spPageC...
  • Nigel Witherdin's avatar
    Feb 09, 2018

    Does it work on a classic page?

     

    In this thread (https://github.com/Microsoft/types-publisher/issues/363) it is mentioned that the SharePoint constants (like _spPageContextInfo) are not supported in modern pages. I think that (as useful as it may be) Mikael Svensson's Spfx web part that allows you to host JavaScript on a modern page should probably be thought of as a hack, and wouldn't be considered supported by MS.

     

    The supported solution would be to create an Spfx web part for your customization, and use the REST call from within it. Within the Spfx web part you can get the current page's context using "this.context.pageContext" - so you can use 

    "this.context.pageContext.web.absoluteUrl" to get the URL of the current web
     
    Thanks
     
    Nigel

Resources