Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to go through all sites belonging a site collection to validate a property bag of them. following is my code. the problem is the second call to get the property uses only one of the sites. I thought it maybe go through sites one by one and get the property bag, but it doesn't. it gets property bag of only one of sites, I think it is the last one.

RootContext = new SP.ClientContext(RootSiteUrl);
SubSites = RootContext.get_web().get_webs();                        
RootContext.load(SubSites);
RootContext.executeQueryAsync(

Function.createDelegate(this, function (sender, args) {
    var subSiteEnum = SubSites.getEnumerator();

    while (subSiteEnum.moveNext()) {

        var Site = subSiteEnum.get_current();

        var SiteContext = new SP.ClientContext(Site.get_url());
        var allProperties = SiteContext.get_web().get_allProperties();                                                                       
        SiteContext.load(allProperties);
        SiteContext.executeQueryAsync(

                Function.createDelegate(this, function (sender, args) {
                    var Prop = allProperties.get_fieldValues()["myProp"];
                    alert(Site.get_title());
                    if (Prop != undefined) {
                        alert(Prop);
                    }
                }),
                Function.createDelegate(this, function (sender, args) {
                    alert('Misslyckades med att hämta property bags för ' + Site.get_title() + ' error: ' + args.get_message());
                })
        );
    }
}),
Function.createDelegate(this, function (sender, args) {
    alert('Misslyckades med att hämta subsiter för s: ' + args.get_message());
})
);      
share|improve this question
1  
I sovled it. For those to want to know, I used JQuery Deferred. I placed the second async query to a deferred method and call the method within the while loop. –  Medes Apr 23 '13 at 12:05
1  
Could you please post it as an answer and mark it as a solution. It should be great if you paste the working solution as well. Thank you. –  Anatoly Mironov Jun 16 '13 at 20:24
    
Using deferred is a nice way to sequentially chain asynchronous callbacks: stackoverflow.com/questions/15504921/… –  Hugh Wood Dec 2 '13 at 10:53
    
@Medes If you solved the issue, please answer your own question as an answer and not as a comment. It'll help others (and you'll have a chance to get upvotes ^^) –  Benny Skogberg Dec 3 '13 at 12:51
add comment

1 Answer 1

up vote 0 down vote accepted

sovled the problem using JQuery Deferred. I placed the second async query to a deferred method and call the method within the while loop.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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