This project has moved and is read-only. For the latest updates, please go here.

"_spUserId is undefined" error when including the ALPHA

Mar 4, 2013 at 1:06 AM
I am catching "_spUserId is undefined" when including the ALPHA in an HTML page in document library and loading HTML page in browser.
<script type="text/javascript" src="jquery.SPServices-2013.01ALPHA2.js"></script>
I assume this is because running from an HTML page in a doc lib is unsupported? Is there a plan to support this scenario? It is much simpler to deploy app to document library than to a customized aspx form. Thanks.
Mar 4, 2013 at 1:11 AM
That variable is defined by the SharePoint JavaScript modules: either init.js or core.js (I don't recall for sure which right now).
So if are simply including SPServices in a plain HTML file, it's not going to work.


Sent from mobile device.

Mar 4, 2013 at 1:59 AM
0.7.2 did not fail on load though, and I can subsequently make calls to SPServices operations on plain HTML page served from document library. Can SPServicesContext() include try blocks in case script not running with init.js/core.js loaded?
Mar 4, 2013 at 2:06 AM
Hmmm. Maybe that's one if the new items Marc is working on. Lets see what he says.

Good luck.


Sent from mobile device.
Mar 4, 2013 at 2:26 AM

You may have seen problems in a plain HTML file if you tried to do anything with the current user in v0.7.2, too. SPServices expects to be used in a SharePoint page, but I can certainly put a check into the new SPServicesContext function to avoid throwing an error if _spUserId isn't available. I'll do this in the next alpha: 2013.01ALPHA3.

Mar 4, 2013 at 2:28 AM
    function SPServicesContext() {
        // SharePoint 2010 gives us a context variable
        if(typeof _spPageContextInfo !== "undefined") {
            this.thisSite = _spPageContextInfo.webServerRelativeUrl;
            this.thisList = _spPageContextInfo.pageListId;
            this.thisUserId = _spPageContextInfo.userId;
        // In SharePoint 2007, we know the UserID only
        } else {
            this.thisSite = "";
            this.thisList = "";
            this.thisUserId = (typeof _spUserId !== "undefined") ? _spUserId : undefined;
Mar 4, 2013 at 3:16 AM
Cool. Thanks for the patch, Marc.