1

How do You use ObjectSharingInformation in javscript?

I get

Uncaught ReferenceError: ObjectSharingInformation is not defined

My function is something like

function getSharingDetails() {

    var clientContext = new SP.ClientContext.get_current();
    var list = clientContext.get_web().get_lists().getByTitle('External Documents');
    var item = list.getItemById(1);

    var objSharingInfo = ObjectSharingInformation.GetObjectSharingInformation(clientContext, item, false, true, false, true, true, true, true);
    clientContext.Load(objSharingInfo);

    clientContext.executeQueryAsync(function () {
        console.log(objSharingInfo.AnonymousViewLink);
        console.log(objSharingInfo.AnonymousEditLink);

    }, function(){});
}

and I load my js like

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {

    // .. 

});

I noticed it is included in sp.js, but I get error. I tried wiki SitePages and Pages libraries, same result..

Hi guys! Thank You much for comments

Now I'm able to get this object, but AnonymousLinks are undefined there

function getSharingDetails() {

    console.log(1);

    var clientContext = new SP.ClientContext.get_current();
    var list = clientContext.get_web().get_lists().getByTitle('External Documents');

    var item = list.getItemById(1);

    var objSharingInfo = SP.ObjectSharingInformation.getObjectSharingInformation(clientContext, item, false, true, false, true, true, true, true);
    clientContext.load(objSharingInfo);


    clientContext.executeQueryAsync(function () {

        console.log(objSharingInfo);
        console.log(objSharingInfo.AnonymousViewLink);
        console.log(objSharingInfo.AnonymousEditLink);

    }, onFail);

}

enter image description here

There is "SharingLinkInfo", but there are no anonymous links.. Still something strange..

Resolved

Thank guys very much!

Your comments helped, and I also forgot lo load list details and there was "undefined". Final snippet:

 var clientContext = new SP.ClientContext.get_current();
        var list = clientContext.get_web().get_lists().getByTitle('External Documents');
        clientContext.load(list); // <-----------
        var item = list.getItemById(2);

        var objSharingInfo = SP.ObjectSharingInformation.getObjectSharingInformation(clientContext, item, false, true, false, true, true, true, true);
        clientContext.load(objSharingInfo);


        clientContext.executeQueryAsync(function () {

            console.log(objSharingInfo);
            console.log(objSharingInfo.get_anonymousEditLink());
            console.log(objSharingInfo.get_anonymousViewLink());

        }, onFail);
  • 1
    try it as SP.ObjectSharingInformation.getObjectSharingInformation(clientContext, item, false, true, false, true, true, true, true) and check – Gautam Sheth Sep 6 '18 at 12:17
  • 1
    Use SP.ObjectSharingInformation – Chicago Sep 6 '18 at 12:25
1

You need to use SP.ObjectSharingInformation.getObjectSharingInformation method.

After that, you need to use a function as get_anonymousEditLink() as a method and not as a property.

Modify the code as below:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {

    var clientContext = new SP.ClientContext.get_current();
    var list = clientContext.get_web().get_lists().getByTitle('External Documents');
    var item = list.getItemById(1);

    var objSharingInfo = SP.ObjectSharingInformation.getObjectSharingInformation(clientContext, item, false, true, false, true, true, true, true);
    clientContext.load(objSharingInfo);

    clientContext.executeQueryAsync(function () {
        console.log("Success")
        console.log(objSharingInfo.get_anonymousEditLink());
        console.log(objSharingInfo.get_anonymousViewLink());

    }, function(){
        console.log("error");
    });

});

Reference - SPObjectSharingInformation in JSOM

  • Thanks, but Gautam, do You get something with objSharingInfo.get_anonymousEditLink()..? I always get 'undefined', but file has anonymous link.. – Gennady G Sep 6 '18 at 12:42
  • Arh!!... I forgot to add 'clientContext.load(list);'... It works! Thank You! – Gennady G Sep 6 '18 at 12:44
  • 1
    @GennadyG Cheers, happy to help ! Looks like somebody downvoted the post answer not sure why , would love to know the reason for the downvote :( – Gautam Sheth Sep 6 '18 at 13:32
  • Hi Gautam! Don't now - I only upvoted!) – Gennady G Sep 6 '18 at 17:34

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.