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

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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