2

Get getting this error on my SP2013 SharePoint Hosted app...randomly...I can just refresh the page and the error resolves itself.

Anyone had this?

Using developer tools the error seems to be connected to the following line.

context = SP.ClientContext.get_current();
web = context.get_web();
userName = web.get_currentUser();
userName.retrieve();
context.load(web, 'EffectiveBasePermissions');
sharePointReady();
// Get the logged in users GH Records
readGhrecords();

context.executeQueryAsync(function () {
    // Success returned from executeQueryAsync
    if (web.get_effectiveBasePermissions().has(SP.PermissionKind.manageWeb)) {
        hideAllPanels();
        initializePeoplePicker('peoplePickerDiv');
        $('#adminMenu').fadeIn(500, null);

    }
    else {
        user = userName.get_title();
        $('#adminMenu').hide();
    }
    user = userName.get_title();


},

Sorry I should have displayed all of the code...it does work but intermittently i get the above error...

S

1
  • This seems to be a JavaScript Client Object error. Can you post your code please? Jan 8, 2014 at 13:42

2 Answers 2

2

I tried to get the effectiveBasePermissions, too. Same error.
The error also says you need to request the EffectiveBasePermissions.

Unhandled exception at line 2, column 31624 in http://app-d9bb496fd62eef.dev.local:10000/_layouts/15/sp.runtime.js

0x800a139e - JavaScript runtime error: The property or field 'EffectiveBasePermissions' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

Update

You need to load the web with the EffectiveBasePermissions

var web = context.get_web();
context.load(web,'EffectiveBasePermissions');
context.executeQueryAsync(onQuerySucceeded, onQueryFailed);

Where in your onQuerySucceeded function you can read out the permissions.

Update

Maybe a workaround, yet not really beautiul. And I'm not sure if it works.

function doStuff(params){
    if (SP.ClientContext == undefined) {
        setTimeout(function() { doStuff(params) }, 100);
        return
    }
    
    context = SP.ClientContext.get_current();
    web = context.get_web();
    userName = web.get_currentUser();
    userName.retrieve();
    context.load(web, 'EffectiveBasePermissions');
    sharePointReady();
    // Get the logged in users GH Records
    readGhrecords();

    context.executeQueryAsync(function () {
        // Success returned from executeQueryAsync
        if (web.get_effectiveBasePermissions().has(SP.PermissionKind.manageWeb)) {
            hideAllPanels();
            initializePeoplePicker('peoplePickerDiv');
            $('#adminMenu').fadeIn(500, null);

        }
        else {
            user = userName.get_title();
            $('#adminMenu').hide();
        }
        user = userName.get_title();


    },
    ...
}

Just write in the comment if it helped. If not I'll delete this snippet.

0

I had this same problem and found that storing the result of get_effectiveBasePermissions(); first within a variable and then using the has() function on this variable helped.

So, instead of

var __current_user_has_permissions = listItem.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)

Try this:

var value = listItem.get_effectiveBasePermissions();
var __current_user_has_permissions = value.has(SP.PermissionKind.editListItems);

I couldn't find a logical explanation for this behavior but making that change reduced the chances of an error.

Update: Good to check for a console error Error: SP.Runtime.js is already loaded. Resolving this error solved the intermittent failure for EffectiveBasePermissions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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