Question

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);
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top