Calling spclientcontext.executeQueryAsync works on the first call, but fails on the second call

I have a webpart that I'm using to display a tree of folders and files from a SharePoint list. When a folder is clicked, some client side code is used to expand the contents of the folder (the code queries the SharePoint list for any child items of the folder).
The code works the first time the folder is clicked. However, if I then click on a sub folder, the code fails. If I click on the sub folder a second time, the code succeeds. This pattern continues - every second time I call my function, it fails.
E.g.
First Click (clicked on Guides), which succeeds, and expands the Guides folder. Second Click (clicked on "In Progress") (fails)
Third Click (clicked on In Progress) (succeeds)
Any ideas why this might happen?
My code looks like this:
var _dweb;
var _dlist;
var _dwebId;
var _dlistId;
var _dfolderUrl;
var _dchildContainerId;
var _dactionContainerId;
var _dlistItems;
var _rtdocsJsInQuery = 0;
function expandorcolapsefolder(webId, listId, folderUrl, parentElementId, childContainerId, actionContainerId) {
var parentElement = $(("#" + parentElementId));
var childElement = $(("#" + childContainerId));
if (parentElement.attr("expanded") == "0") {
parentElement.attr("expanded", "1");
childElement.css("display", "block");
} else {
parentElement.attr("expanded", "0");
childElement.css("display", "none");
return;
if (childElement.attr("dataretrieved") == "0") {
GetData(webId, listId, folderUrl, childContainerId, actionContainerId);
function GetData(webId, listId, folderUrl, resultsElementId, actionContainerId) {
if(_rtdocsJsInQuery==1)
alert('Please wait for the previous action to finish, before trying again.');
_rtdocsJsInQuery = 1;
_dchildContainerId = resultsElementId;
_dactionContainerId = actionContainerId;
_dwebId = webId;
_dlistId = listId;
ShowActionContainer(actionContainerId);
try {
var context = new SP.ClientContext.get_current();
_dweb = context.get_web();
_dlist = _dweb.get_lists().getById(listId);
var query = new SP.CamlQuery();
query.set_viewXml('<View><OrderBy><FieldRef Name="Title"/><FieldRef Name="FileLeafRef"/></OrderBy></View>');
query.set_folderServerRelativeUrl(folderUrl);
_dlistItems = _dlist.getItems(query);
context.load(_dweb);
context.load(_dlist);
context.load(_dlistItems, 'Include(ID,Title,DocIcon,_dlc_DocIdUrl,DisplayName,FileSystemObjectType,FileLeafRef,ServerUrl)');
context.executeQueryAsync(QuerySuccessful,QueryFailed);
} catch (e) {
alert("Failed to execute query... " + e);
HideActionContainer(actionContainerId);
function QuerySuccessful(sender, args) {
try {
// Code omitted.
} catch (error) {
alert("Failed to process query results... " + error);
_rtdocsJsInQuery = 0;
window.setTimeout(HideActionContainer(_dactionContainerId), 500);
function QueryFailed(sender, args) {
alert('Failed to get list items. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
_rtdocsJsInQuery = 0;
HideActionContainer(_dactionContainerId);
Regards, Matthew
MCPD | MCITP
My Blog
View
Matthew Yarlett's profile
See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
Upload and Crop User Profile Photos

I fixed this problem by initialising the clientcontext object with a URL (rather than using the get_current property). This suits my needs, as the web that the page the webpart is on, won't always be in the same web as the list.
I'm still unsure why  "var context = SP.ClientContext.get_current();" fails every second time?!
Here's the snippet of code I changed, for others reference (namely "var ctx = new SP.ClientContext('/weburl');"):
function GetData(webId, listId, folderUrl, resultsElementId, actionContainerId) {
if(_rtdocsJsInQuery==1)
alert('Please wait for the previous action to finish, before trying again.');
return;
_rtdocsJsInQuery = 1;
_dchildContainerId = resultsElementId;
_dactionContainerId = actionContainerId;
_dwebId = webId;
_dlistId = listId;
ShowActionContainer(actionContainerId);
try {
var ctx = new SP.ClientContext('/eog');
_dweb = ctx.get_web();
_dlist = _dweb.get_lists().getById(listId);
var query = new SP.CamlQuery();
query.set_viewXml('<View><OrderBy><FieldRef Name="Title"/><FieldRef Name="FileLeafRef"/></OrderBy></View>');
query.set_folderServerRelativeUrl(folderUrl);
_dlistItems = _dlist.getItems(query);
ctx.load(_dweb);
ctx.load(_dlist);
ctx.load(_dlistItems, 'Include(ID,Title,DocIcon,_dlc_DocIdUrl,DisplayName,FileSystemObjectType,FileLeafRef,ServerUrl)');
ctx.executeQueryAsync(QuerySuccessful,QueryFailed);
return true;
} catch (e) {
alert("Failed to execute query... " + e);
HideActionContainer(actionContainerId);
return false;
Regards, Matthew
MCPD | MCITP
My Blog
View
Matthew Yarlett's profile
See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
Upload and Crop User Profile Photos

Similar Messages

  • Why do text variables using Running Header character style translate forced returns as a word space in the running head on the first page but close up the space on subsequent pages?

    In an InDesign document that requires 3 different Chapter head paragraph styles (to cope with differrent length headings) I've set up the running heads on the master page with a text variable using the Running header (character style) option. The character style I've assigned to this is an empty character style that is applied to all 3 chapter head paragraph styles.
    Some chapter heads require a forced line break, so that the line breaks are aethesically pleasing. On the first page the text variable translates this forced line break as a word space in the running head, but on subsequent pages it ignores the forced line break. This means that if you have a word space before the forced line break, on the first page you get a double word space and on subsequent pages the running head sets correctly with a single word space. But if you remove the word space before the forced line break in the chapter head text, the first running head sets correctly with forced line break interpreted as a single word space, but on subsequest pages the space is closed up.
    This only seems to be a problem when the character style option is used for header text variables. If a paragraph style is used the forrced line break is interpreted as a a single word space in all instances, both on the foirst page and subsequent pages.
    This would appear to be a bug in how text variables are applied when using the Running header (character style) option. I can't see any other reason why the text variable would beheave differently on the first page and on subsequent pages. There is only one master page, so it isn't a case of their being an error between a main master page and a chapter opener master page.
    Does anyone have any solutionss, or know if this problem has been fixed in subsequent releases of InDesign (I'm using CS6 ID version 8.0)
    Thanks

    Ask in the ID forum...
    Mylenium

  • Since i update my iPhone 5 with IOS 7.0.2, I start to have serious problems to call or receive calls from other telephones: is not possible to open the call at the first try. Somebody have the same problem?

    Since i update my iPhone 5 with IOS 7.0.2, I start to have serious problems to call or receive calls from other telephones: is not possible to open the call at the first try. Somebody have the same problem?

    Try
    Reset: Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Note: You will not lose any data

  • All data and messaging works on my note 4, but last night the cellular phone service just went dead.  I can call people but the line is just silent, and people can call me, it rings, but I can't hear them.  ?????

    all data and messaging works on my note 4, but last night the cellular phone service just went dead.  I can call people but the line is just silent, and people can call me, it rings, but I can't hear them.  ????? What is wrong with it????  How do I fix it????

    You aren't attached to a bluetooth headset or other device for some strange reason?  Or even an automobile bluetooth, I have a friend that has this issue with his Prius because even when it is not running the bluetooth is still active and connects to his phone.

  • BDC with call transaction VD02 works fin in A mode but not in N mode

    Hi All,
        I have BDC program developed in 4.6c using call transaction VD02 works fine with mode A but not with mode N.
    Now we upgraded to ECC 6.0.Do I need to change anything?

    No, you don't have to change anything for ECC. BTW, I wonder why VD02 is not working in the background for you?

  • So my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    so my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    I got the same problem. The percentage of getting this problem is around 10% of all my dial/receive calls.
    The problem usually appears when I receive calls. The phone app will freeze, and I cannot dial or receive calls even I closed the phone app, however, most other apps work properly.
    Once this problem happens, I will not be able to turn off the phone by holding sleep button, the only way I can get rid of it is holding sleep and home button at the same time to reset the iphone.

  • Help please - have a Nano and a Shuffle and neither are working! The Nano wheel appears to have stopped working - I can't get it to do anything. I've done the reset,it worked the first time but not since. And the shuffle won't sync with my library!

    Hi,
    I have an iPod shuffle 4th generation and an iPod Nano 5th generation . The Nano wheel appears to have stopped working - I can't get it to play or anything. I've done the reset and it worked the first time, but now the only way I can get it to play anything is to shake it and go with the shuffle choices - I can't change volume, song, pause or turn it off.
    So, I decided to start using the Shuffle which I was given as a present last year. I've plugged it into my laptop (running windows 8 and newest version of iTunes). It appears in iTunes on the left hand side, but when I click to sync (whether I tick sync all or choose artists) it says synched but has no music. It seems to not be linked to the music library - when I tick synch all songs, next to the "sync music" it says 0 songs?
    Any help to fix either would be really appreciated - I'm without any music at the moment and I'm going away this weekend!
    Thanks

    Hi Bblairjones,
    If you are having issues with your Nano and Shuffle, you may want to try the Troubleshooting Assistants on the following page:
    Apple Support: iPod Troubleshooting Assistants
    http://www.apple.com/support/ipod/five_rs/
    Regards,
    - Brenden

  • I just download and install itunes 10.5 and it worked good the first days but since yesterday it crashed up, and everytime i start it it crashes again and logged me out each time. it can´t acces my itunes account. I´m using snow leopard the last version.

    I just download and install itunes 10.5 and it worked good the first days but since yesterday it crashed up, and everytime i start it it crashes again and logged me out each time. it can´t acces my itunes account. I´m using snow leopard the last version. What can i do to solve this problem and and continue using my itunes normally?

    Try doing it in a WIndows Safe mode - Restart computer and hit F8 key right after your see BIOS check and choose "Safe mode with networking"
    Do the SFC /SCANNOW again.
    If that does not work, whilst in safe mode, download Free Malwarebyte software from CNET's Download.com.  Install, update virus definition then perform a full scan.  Remove if it did find some viruses or trojans.  Restart computer.
    Back to regular windows, do the SFC /SCANNOW again.
    If that doesnot work, check to see if your Hard drive has errors or bad sectors
    GO START BUTTON /COMPUTER, right mouse click OS (C:) and choose "Properties"
    Choose "Tools" tab and under error checking, click "Check Now".
    Make sure "Scan for and attempt recovery of bad sectors" is checked and click start.
    Restart windows will perform the above task to fix errors  This may take hours depends on how big is your Hard Drive
    Good Luck!!.

  • I've installed itunes twice. It worked the first time but after I restarted my computer it kept giving me this message: Itunes was not correctly installed. Please reinstall itunes. Error 7 (Windows error 127). What's wrong?

    I've installed itunes twice. It worked the first time but after I restarted my computer it kept giving me this message: Itunes was not correctly installed. Please reinstall itunes. Error 7 (Windows error 127). What's wrong?

    See the second box in Troubleshooting issues with iTunes for Windows updates.
    tt2

  • My MacBook Pro is crashing and Mac OS stops working sometimes so I have to restart it. And sometimes it stays on the first white-ish screen with the Apple and won't start further. What to do?

    my MacBook Pro is crashing and Mac OS stops working sometimes so I have to restart it. And sometimes it stays on the first white-ish screen with the Apple and won't start further.
    What to do?
    Does that mean that the is the end of my Mac Book 5bought in the summer of 2009) ? Or is there someting to do to fix it?
    Thanks
    V

    Try this:
    How to Perform an Archive and Install
    An Archive and Install will NOT erase your hard drive, but you must have sufficient free space for a second OS X installation which could be from 3-9 GBs depending upon the version of OS X and selected installation options. The free space requirement is over and above normal free space requirements which should be at least 6-10 GBs. Read all the linked references carefully before proceeding.
    1. Be sure to use Disk Utility first to repair the disk before performing the Archive and Install.
    Repairing the Hard Drive and Permissions
    Boot from your OS X Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger, Leopard or Snow Leopard.) After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list. In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive. If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer. Now restart normally.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Do not proceed with an Archive and Install if DU reports errors it cannot fix. In that case use Disk Warrior and/or TechTool Pro to repair the hard drive. If neither can repair the drive, then you will have to erase the drive and reinstall from scratch.
    3. Boot from your OS X Installer disc. After the installer loads select your language and click on the Continue button. When you reach the screen to select a destination drive click once on the destination drive then click on the Option button. Select the Archive and Install option. You have an option to preserve users and network preferences. Only select this option if you are sure you have no corrupted files in your user accounts. Otherwise leave this option unchecked. Click on the OK button and continue with the OS X Installation.
    4. Upon completion of the Archive and Install you will have a Previous System Folder in the root directory. You should retain the PSF until you are sure you do not need to manually transfer any items from the PSF to your newly installed system.
    5. After moving any items you want to keep from the PSF you should delete it. You can back it up if you prefer, but you must delete it from the hard drive.
    6. You can now download a Combo Updater directly from Apple's download site to update your new system to the desired version as well as install any security or other updates. You can also do this using Software Update.

  • Hello! I have installed Photoshop on PC WIN 7 64bit. When I store first time a Photoshop docuument, it works fine - after re-opening and doing changes I trying again to store it - it does not work anymore! First it does not accept the name (message "It ca

    Hello! I have installed Photoshop on PC WIN 7 64bit. When I store first time a Photoshop docuument, it works fine - after re-opening and doing changes I trying again to store it - it does not work anymore! First it does not accept the name (message "It can not be stored because the nam is invalid" With 2. trial it tells me that the data is blocked and I don't have the rights - and I should chenge them. But I am working as the Admin on my PC - and each trial to change the rights of the data is as well not possible because of missing rights - even I am Admin! I must always store the data with a new name, then it works, but I also cannot remove the old datas or shift them into the waste paper - because of no rights! -- sorry for not perfect english, I am German native speaker! Tahnks a lot for help!

    Hi,
    I am using a Nvidia 4200M adapter in my Laptop, Driver 266.96, Direct X 11
    In my desktop I am using an ATI XFX 6950, latest revision drivers (I am not at home right now so I cant get that info).
    The issue I did describe above, but it was a long explanation.
    In some flash games the game files load initially and get as far as the "click to start" button. Then the flash area usually goes either all white or all black (usually depending on the falsh game default background color) and then it stays that color. Cant see anything after hitting start (usually most games have an intro video or animation before the game starts, but I cant see any of it.
    For the very few games that do start, the flash game or application does not seem to work correctly in that when the rare game starts, it wont save any game files or save files to the pc and so if I exit the game (navigate away to another page or close browser) and then later come back, even though I click the option to save games (and ensure that the flash application slider shows it can save files and lots of space) it does not save and I have to start from the beginning all the time.
    More explanation I gave above.

  • I bought a camera connection kit. First time it worked fine, using the USB connector, but now neither the USB or SD connector works. The iPad shows a connector is attached, but Photos doesn't open. Any ideas? thanks

    I bought a camera connection kit. First time it worked fine, using the USB connector, but now neither the USB nor SD connector works. The iPad shows a connector is attached, but Photos doesn't open. Any ideas? thanks

    If you have not done so, try exiting the Photo app (and maybe more apps if you have a lot open) from the Open Apps List and see if a discount/reconnect opens the app. If that does not work, try powering down the iPad and test. If it is still not working try a hard reset by pressing both Home and Sleep/Wake buttons at the same time until the Apple graphic appears, ignoring the Slide to Power Off button.

  • HT1349 I recently bought an iPhone and my charger is not working. It worked for the first time but now it is now it is not working. Can i get it replaced in India because i bought this phone from US?

    I recently bought an iPhone and my charger is not working. It worked for the first time but now it is now it is not working. Can i get it replaced in India because i bought this phone from US?

    The warranty is only good in the U.S.
    You woulod have to send it to someone in the U.S.  They could take it in and if it is defective, then it would be replaced.

  • How can I disable making live shape rectangle in the first place but normal one instead in Illustrator CC?

    How can I disable making live shape rectangle in the first place but normal one instead in Illustrator CC? When I create rectangle I can't transform it by dragging and it's only the problem with rectangle, not with circle, star etc. I try show/hide edges/bounding box reset preferences and reinstall whole illustrator CC and it's the same. I can only make this right by expand this rectangle, which is shape as is turn out to rectangle by clicking object>shape>expand rectangle. But this is so frustrating. Help!:) oh, and I use OSX. My friend has the same specs and it's works. I mean she can use live shape corner transformations and changing size by draging:(

    I’ve created my own plugin (available for free for personal and commercial use) which imitates behavior of the ‘old’ Rectangle Tool. It doesn’t replace the Live Rectangle – it works completely independent!
    My Plain Rectangle Tool correctly snaps to grids/objects/points and correctly aligns to grid/points on resize. Of course it supports the SHIFT and ALT/OPTION keys, Snap to Grid and Smart Guides options. In other words it works almost 100% the same as the Rectangle Tool we know from CC (17.1), CS6 and earlier.
    The installation package (zxp) adds ‘Plain Rectangle Tool’ icon into the Ai panel (of curse you can assign your custom keyboard shortcut to it as well)
    Note: The Plain Rectangle can be easily converted into the Live one using Object > Shape > Convert to Rectangle
    Grab your copy at http://63mutants.com/subc/products/PlainRectangleTool_m01/PlainRectangleTool_m01.php Feel free to share with your friends. It’s completely free.
    I’ve also created a separate discussion https://forums.adobe.com/thread/1587587 for the Plain Rectangle Tool. If you have any comments or request please post it there. Any feedback would be greatly appreciated!
    Thanks,
    Pawel Kuc

  • Using photoshop elements 13 for a brochure Drew the rectangle shape for the first column but when i go to use the move tool it doesnt highlite the rectangle box why?

    Using photoshop elements 13 for creating a brochure -drew the rectanle shape for the first column but when i go to the move tool it doesnt allow me to highlite this shape why?

    The faulting module is photoshop. Report below.
    Source
    Adobe Photoshop CC 2014
    Summary
    Stopped working
    Date
    2/2/2015 4:54 PM
    Status
    Report sent
    Description
    Faulting Application Path: C:\Program Files\Adobe\Adobe Photoshop CC 2014\Photoshop.exe
    Problem signature
    Problem Event Name: APPCRASH
    Application Name: Photoshop.exe
    Application Version: 15.2.2.310
    Application Timestamp: 5480338c
    Fault Module Name: Photoshop.exe
    Fault Module Version: 15.2.2.310
    Fault Module Timestamp: 5480338c
    Exception Code: c000001d
    Exception Offset: 00000000049de322
    OS Version: 6.3.9600.2.0.0.768.101
    Locale ID: 1033
    Additional Information 1: 8db4
    Additional Information 2: 8db473619c10c0c8b85ce99afe676ed8
    Additional Information 3: f06d
    Additional Information 4: f06da704bdd5338df2a8d09bde2244bb
    Extra information about the problem
    Bucket ID: 1fe6d1d4e5765bd348843b981b8ec4d2 (85990875000)

Maybe you are looking for