So, I can either sound like I'm the nicest guy in the world and say I threw together a little script to make your life easier when testing your CAML queries, or I can be honest and say I'm tired of people saying my scripts don't work because they don't know how to write CAML queries…hmmm.. Which to choose... Which to choose…
Regardless, one of the biggest problems when using SharePoint's Web Services, The Client Object Model, or SPServices is tracking down problems in your scripts. Sometimes it's hard to know if your CAML query is wrong or if it's something else in your script. How do you even know if your CAML query is returning the right information??
Well, to help you out I created the very simple script that you can download here. I even made the links to jQuery and SPServices external so all you have to do is drop this puppy in to do you testing. Please note, this script is NOT meant to help you *build* your queries. There are other tools for that. This is purely a testing tool to help you during those "doh" moments.
The script works as follows:
- Input your target list name
- Input the desired View Fields (using the correct syntax)
- Input your CAML query (using the correct syntax)
- Press the "Execute Query" button.
Your results will be displayed in a table next to the "Query Results" label. If an error occurs it will also be displayed in the Query Results table. Once you have your query written correctly, you can just copy it out of the text box and past it into your solution.
The script also comes with some default information entered into the text boxes so you can get used to the basic syntax of the queries. You can see a live demo of the script here.
That's it! Short and sweet… now go enjoy your weekend.