11

Any ideas why I'm only getting 0 or false, but never true for result.get_value()?

// Set IsFollowed correctly.
var clientContext = SP.ClientContext.get_current();
var socialManager = new SP.Social.SocialFollowingManager(clientContext);
var socialActor = new SP.Social.SocialActorInfo();
socialActor.set_contentUri(url);
socialActor.set_actorType(SP.Social.SocialActorType.site);
result = socialManager.isFollowed(socialActor);
clientContext.executeQueryAsync(
    function () {
        if (result.get_value())
        {
            this.IsFollowed = ko.observable(true);
        }
        else
        {
            this.IsFollowed = ko.observable(false);
        }
        //alert("IsFollowed = " + this.IsFollowed);
    },
    function (sender, args) {
        // Failed.
        alert('Error: ' + args.get_message());
    }
);

I am doing the above when pushing to an observablearray in knockout.js, and wait for the social manager to load:

        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
        // Make sure SocialFollowingManager is available
        SP.SOD.executeFunc('userprofile', 'SP.Social.SocialFollowingManager',             
        function () {
            //ko.applyBindings(new LinksViewModel(), document.getElementById("springim-core-menu-list-links"));
            ko.applyBindings(new MyQuickLinksViewModel(), document.getElementById("springim-myquicklinks"));
            ko.applyBindings(new MyFollowedSitesViewModel(), document.getElementById("springim-core-menu-list-followedsites"));
        });
    });

Oddily enough, I use the same code elsewhere when the page has loaded on a click event and it reads the value correctly (just true/false).

Regards,

Ben

1 Answer 1

0

May be you are getting random results because the "result" variable is a global variabile. Try to put a "var" before it to make it local
var result = socialManager.isFollowed(socialActor);

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.