2
votes

I'm looking for a function or code snippet or some starting help in creating a CAML builder in JavaScript.

Building nested ORs shouldn't be a problem, e.g. (pid == 101 || pid == 102 || pid == 105) It's just a case of wraping groups of two in tags. Similar for AND.

Where I'm struggiling is combining ORs and ANDs in the same query. Generally we will have a series dropdown boxes or checkboxes the user selects from. They can choose the not select certain fields which is why I need to build the CAML dynmically rather than have it ready to go and just inject the values into the appropriate places.

EDIT: Here's what I have so far http://jsfiddle.net/QSPj2/4/

So far it only builds either a series of ORs or a series of ANDs. You pass in an array of objects. Each object has field, comparison, type and value. The CAML builder will take this array and generate properly nested ANDs or ORs. Use Dreamweaver formatting tool or similar on the output CAML to make it easier to read.

It gets going to get a lot more tricky trying to combine ANDs with ORs.

1

1 Answers