Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

executeQueryAsync() is not working properly using ecma script

$
0
0

Hi all,

- I have 2 sites (A and B) both in the same Site Collection.

- Site A contains library LibX.

- Site B contains a bunch of sub-sites (same structure) and each contains library LibY.

- LibX contains number of documents

- All LibY libraries should contain one or more documents which name is based on the document name in LibX (also subsites are based on the same name)

What I did so far is following:

- Collected list of document names in LibY and stored them in array FileNames

- Collected list of all sub-site names in site B (using get_webs()) and stored them in SiteNames array

- For each File in FileNames checked if there is matching Site in SiteName (notification to tell me if I need to create sub-site)

* problem starts here *

- When match is found I call checkIfLibYexists function in executeQueryAsync() - there is about 20 matches

- in checkIfLibYexists I have following:

var context =  new SP.ClientContext(<subsite>);

this.lists = context.get_web().get_lists();

context.load(lists); // until this point everything looks ok

executeQueryAsync(Function.createDelegate(this, this.onSuccess), ...) // when I have only one match this works, when I have more than one match when checking onSuccess function it looks like it executed executeQueryAsync only for the last subsite making call multiple times.

in onSucess function when trying to get a library title (or anything else) I've get the error: The collection has not been initialized.

The next step I'm planning to add is to create LibY if it doesn't exist or to check if documents I mentioned at the beginning exist in the LibY (if not to upload them or create link to a document in libX)

I'm pretty new in this so I wonder how to do it and where I'm making mistake.

-------- what script needs to do ------------

- Collect FileNames from SiteA/LibX

- Collect SiteNames stored under SiteB

- For each File in FileNamescheck if there is a match in SiteNames

         if there is no match: send notification to me so I can create subsite later

         else check if LibY library in Site that maches

                 if LibY does not exists  send notification to me so I can create LibY later

                 else check if set of files are stored in LibY

                        if files are not there: upload or create link to a document for those files

                        else notify me that files are OK

------------------

Any help is more than appreciated.

Thanks



Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>