2

I've got a pretty weird issue going on on a clients SharePoint 2013 environment. We're using some JSOM javascript code to retrieve details from a web. Here is a snippet of the code:

function getSiteProperties() {
    var deferred = $.Deferred();

    var ctx = SP.ClientContext.get_current();
    var web = ctx.get_web();
    var siteProps = web.get_allProperties();
    var user = web.get_currentUser();

    var ob = new SP.BasePermissions();
    ob.set(SP.PermissionKind.manageWeb)
    var hasPermissions = web.doesUserHavePermissions(ob)

    ctx.load(user);
    ctx.load(siteProps);

    ctx.executeQueryAsync(
        function () {
            deferred.resolve(siteProps, user.get_isSiteAdmin(), hasPermissions.get_value());
        },
        function (sender, args) {
            deferred.reject(sender, args);
        }
    );

    return deferred.promise();
}

var displaySiteStatus = function () {
    getSiteProperties().then(function (props, isSiteAdmin, isOwner) { displayMessage(props, isSiteAdmin, isOwner); });
}

This has been tested on another environment and found working. Now deploying it to the client environment, the objects returned by the object model are instantiated, but not filled with data. No matter what property I try to read, everything gives the same error message;

The property or field 'IsSiteAdmin' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

It seems to be a platform related thing since the same code works fine elsewhere. But I have no clue and I don't have access to the platform to peek in the logs or something.

  • It should work, but could you try: ctx.load(user, 'IsSiteAdmin'); – Anders Aune Jan 20 '16 at 13:17
  • Jup tried that, makes no difference. I also tried another site collection, weirdly it works like a charm on that one. – Jasper Jan 21 '16 at 10:17
  • Have you tried fetching the property with REST ? – Anders Aune Jan 22 '16 at 7:37
0

I'm not sure where you are referencing title since it isn't in your method.

If I execute the following code both objects contain the data I would expect when the done method executes.

getSiteProperties().done(
    function(data,user){
        console.log(data);
        console.log(user);
    }
);

Are you sure you are working with the deferred object correctly? You can read more here.

  • Sorry the error was taken from a different piece of code, as said it doesn't matter which property I try to read. The same code runs fine on a different environment so I would say we can pretty much rule out any real coding errors. – Jasper Jan 18 '16 at 17:43
  • Can you give an example of how you are using this code? – Gilgamesh Jan 18 '16 at 18:35
  • I cannot share the whole file, it's client source code. What exactly would you want to see? I don't completely see how this is relevant since the code is functioning, the platform isn't. – Jasper Jan 18 '16 at 21:16
  • Given that you posted this code as what you suspect is the cause of the issue, I'm curious as to how you are using the this method and the promise it returns as well as what properties you are trying to reference once the promise is resolved. – Gilgamesh Jan 19 '16 at 13:10
  • Ok, so I added the calling code and what happens with the promise. Routine itself changed a bit too, just to make it more clear. Note that the resolve of the promise is not hit because the error already happens on calling user.get_isSiteAdmin(). – Jasper Jan 19 '16 at 13:57

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.