Quantcast
Channel: CamlJs: SharePoint JavaScript Caml Builder
Viewing all 199 articles
Browse latest View live

New Post: Build CAML query from Array

$
0
0
If you are on sharepoint2007 you also need sp.core.js and sp.runtime.js. You can get it from some existing Sharepoint2013 site.

New Post: Is this Tool support join between lists?

$
0
0
Dear all,
Could you please help me. Is this Tool support join between lists?

Thanks and Regards!

New Post: Is this Tool support join between lists?

$
0
0
Hi,

Unfortunately, list joins aren't supported by this tool.

Created Unassigned: Unable to get property 'create' of undefined or null reference [4]

$
0
0
Hi,
I am using this tool for the first time and I am getting following error:

Unable to get property 'create' of undefined or null reference

Here is my jquery code:
var camlBuilder = new CamlBuilder();

var Query = camlBuilder.Where()
.TextField("Evidence").EqualTo("test")
.Or()
.TextField("LinkTitle").BeginsWith("1.01.")
.ToString();

Updated Release: Release 2.1

$
0
0
(planning)

  1. View element full coverage
    • ViewFields
    • QueryOptions
    • View element attributes
    • etc.
  2. ToCamlQuery() method, returns SP.CamlQuery object
  3. For SP2007 users - create a file with SP.XmlWriter and Sys.StringBuilder classes copied out from SP2010
  4. Include support for loading camljs on-demand (via SP.SOD)
  5. Add overloads to All & Any accepting arrays
  6. Documentation and examples for dynamic creation of CAML queries based on js arrays
  7. Mercurial -> Git
  8. Convert the example project to be SharePoint-hosted App

Reviewed: Release 2.0 (Jul 08, 2014)

$
0
0
Rated 5 Stars (out of 5) - This is solid. I am using it for an Employee Directory app in o365. We have to dynamically build several queries and this saved me a lot of time. No issues thus far. Running in production with several thousand hits per day.

Source code checked in, #9a5612cb19de6b849625adaab4104e78cd7c3ec0

$
0
0
camljs.spdeps.js for standalone/sp2017

Released: Release 2.0 (Aug 26, 2013)

$
0
0

Bracket expressions and partial query generation

This is the main improvement comparing to the version 1.0, where you couldn't create complex queries because of lack of bracket expressions support.

Two new methods were added to the builder chain in order to support that: Any&All.

/** Adds And clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
All(...conditions: IExpression[]): IExpression;

/** Adds Or clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
Any(...conditions: IExpression[]): IExpression;

You can use these methods in conjunction with CamlBuilder.Expression() for creating bracket expressions, for example like this:
var camlQuery = new CamlBuilder().Where().Any(
    CamlBuilder.Expression().TextField("Email").EqualTo("support@google.com"), 
    CamlBuilder.Expression().TextField("Email").EqualTo("plus@google.com"), 
    CamlBuilder.Expression().TextField("Title").BeginsWith("[Google]"), 
    CamlBuilder.Expression().TextField("Content").Contains("Google")
).ToString();


As a side effect, you can now create parts of your query separately via CamlBuilder.Expression(), and then merge them together at some point later. Also you can useCamlBuilder.Expression() for defining CAMLQuery attribute in SPServices.

Better Intellisense

Intellisense significantly improved: now different types of fields have different sets of comparison options. Field usage is made more obvious.
  1. LookupField element improved. No more misleading "casting" of lookups to the target field types: now lookup fields expose methodsId() and ValueAs<type of field>().
  2. BooleanField element added for fields of boolean type.
  3. UrlField element added for fields of type URL.
  4. DateRangesOverlap element improved. It turns out, you cannot use this element in CSOM, because CSOM ignores QueryOptions element. But you still can use DateRangesOverlap with SPServices.
  5. UserField element improved.

Migration from version 1.0 to version 2.0

None of old elements were removed, but syntax is now more strict, thus in some cases it is possible that some migration will be necessary. Please, post your problems to discussions, if you will have any.

Also, please keep in mind that some elements were marked as deprecated:
  1. LookupIdField element marked as deprecated and will be removed in the next major release. Please, useLookupField(...).Id() instead.
  2. Membership element marked as deprecated and will be removed in the next major release. Functionality ofMembership element was replaced with set of methods under UserField element.

TypeScript implementation

CamlBuilder is now implemented in TypeScript and thus can be used seamlessly by Typescript developers. Of course, you can still use JavaScript version for pure JS development.

Internally, TypeScript unit tests (tsUnit) are now used, helping to make the library much more stable. New tests are added.

Nuget

CamlBuilder is now available via Nuget.

JavaScript:

PM> Install-Package CamlJs


TypeScript definitions:

PM> Install-Package camljs.TypeScript.DefinitelyTyped

Updated Release: Release 2.0 (elo 26, 2013)

$
0
0

Bracket expressions and partial query generation

This is the main improvement comparing to the version 1.0, where you couldn't create complex queries because of lack of bracket expressions support.

Two new methods were added to the builder chain in order to support that: Any& All.

/** Adds And clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
All(...conditions: IExpression[]): IExpression;

/** Adds Or clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
Any(...conditions: IExpression[]): IExpression;

You can use these methods in conjunction with CamlBuilder.Expression() for creating bracket expressions, for example like this:
var camlQuery = new CamlBuilder().Where().Any(
    CamlBuilder.Expression().TextField("Email").EqualTo("support@google.com"), 
    CamlBuilder.Expression().TextField("Email").EqualTo("plus@google.com"), 
    CamlBuilder.Expression().TextField("Title").BeginsWith("[Google]"), 
    CamlBuilder.Expression().TextField("Content").Contains("Google")
).ToString();


As a side effect, you can now create parts of your query separately via CamlBuilder.Expression(), and then merge them together at some point later. Also you can use CamlBuilder.Expression() for defining CAMLQuery attribute in SPServices.

Better Intellisense

Intellisense significantly improved: now different types of fields have different sets of comparison options. Field usage is made more obvious.
  1. LookupField element improved. No more misleading "casting" of lookups to the target field types: now lookup fields expose methods Id() and ValueAs<type of field>().
  2. BooleanField element added for fields of boolean type.
  3. UrlField element added for fields of type URL.
  4. DateRangesOverlap element improved. It turns out, you cannot use this element in CSOM, because CSOM ignores QueryOptions element. But you still can use DateRangesOverlap with SPServices.
  5. UserField element improved.

Migration from version 1.0 to version 2.0

None of old elements were removed, but syntax is now more strict, thus in some cases it is possible that some migration will be necessary. Please, post your problems to discussions, if you will have any.

Also, please keep in mind that some elements were marked as deprecated:
  1. LookupIdField element marked as deprecated and will be removed in the next major release. Please, use LookupField(...).Id() instead.
  2. Membership element marked as deprecated and will be removed in the next major release. Functionality of Membership element was replaced with set of methods under UserField element.

TypeScript implementation

CamlBuilder is now implemented in TypeScript and thus can be used seamlessly by Typescript developers. Of course, you can still use JavaScript version for pure JS development.

Internally, TypeScript unit tests (tsUnit) are now used, helping to make the library much more stable. New tests are added.

Nuget

CamlBuilder is now available via Nuget.

JavaScript:

PM> Install-Package CamlJs


TypeScript definitions:

PM> Install-Package camljs.TypeScript.DefinitelyTyped

Source code checked in, #590b4dfd01a7b7135771dfdc156c92880911082d

$
0
0
minor refactoring. the "run the tests" code is now in the html/aspx files rather than in js files this allows to keep Tests.js same for both SP-dependent and standalone versions

New Post: Ability to join existing CAML query string

$
0
0
Hello,

It would be nice to have an ability to compose/join already existing CAML query string with the one from CamlJs.

For instance, we would like to run caml query against particular list view.
We grab existing caml query from the list view, construct additional caml query with camljs, and.... and would be nice to get these two queries composed.

Would it be something to see in the future releases?
Is there any recommended workaround?

Thanks!

New Post: Ability to join existing CAML query string

$
0
0
Unfortunately, right now it is not supported, and I can't think of any quick workaround.

I'm now working on the next release which you can find in the planning releases under Downloads tab.
There are quite a few new features planned, so I'm not sure I'll be able to fit it in.

On the other hand, the case you mentioned seems to be a frequent one, I did same myself many times, in server code.
So I reckon this feature deserves to be implemented sooner or later.

Thanks for your feedback!

Updated Wiki: Home

$
0
0

Project Description

Simplifies creation of SharePoint CAML queries for client-side scripts. Can be used with either SharePoint Client Object Model or SPServices.

Nuget:

PM> Install-Package CamlJs

What's new in Release 2.0

Bracket expressions and partial query generation

This is the main improvement comparing to the version 1.0, where you couldn't create complex queries because of lack of bracket expressions support.

Two new methods were added to the builder chain in order to support that: Any& All.

/** Adds And clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
All(...conditions: IExpression[]): IExpression;

 

/** Adds Or clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
Any(...conditions: IExpression[]): IExpression;


You can use these methods in conjunction with CamlBuilder.Expression() for creating bracket expressions, for example like this:

var camlQuery = new CamlBuilder().Where().Any(
    CamlBuilder.Expression().TextField("Email").EqualTo("support@google.com"), 
    CamlBuilder.Expression().TextField("Email").EqualTo("plus@google.com"), 
    CamlBuilder.Expression().TextField("Title").BeginsWith("[Google]"), 
    CamlBuilder.Expression().TextField("Content").Contains("Google")
).ToString();


As a side effect, you can now create parts of your query separately via CamlBuilder.Expression(), and then merge them together at some point later. Also you can useCamlBuilder.Expression() for defining CAMLQuery attribute in SPServices.

Better Intellisense

Intellisense significantly improved: now different types of fields have different sets of comparison options. Field usage is made more obvious.

  1. LookupField element improved. No more misleading "casting" of lookups to the target field types: now lookup fields expose methodsId() and ValueAs<type of field>().
  2. BooleanField element added for fields of boolean type.
  3. UrlField element added for fields of type URL.
  4. DateRangesOverlap element improved. It turns out, you cannot use this element in CSOM, because CSOM ignores QueryOptions element. But you still can use DateRangesOverlap with SPServices.
  5. UserField element improved.

Migration from version 1.0 to version 2.0

None of old elements were removed, but syntax is now more strict, thus in some cases it is possible that some migration will be necessary. Please, post your problems to discussions, if you will have any.

Also, please keep in mind that some elements were marked as deprecated:

  1. LookupIdField element marked as deprecated and will be removed in the next major release. Please, useLookupField(...).Id() instead.
  2. Membership element marked as deprecated and will be removed in the next major release. Functionality ofMembership element was replaced with set of methods under UserField element.

TypeScript implementation

CamlBuilder is now implemented in TypeScript and thus can be used seamlessly by Typescript developers. Of course, you can still use JavaScript version for pure JS development.

Internally, TypeScript unit tests (tsUnit) are now used, helping to make the library much more stable. New tests are added.

Nuget

CamlBuilder is now available via Nuget.

JavaScript:

PM> Install-Package CamlJs



TypeScript definitions:

PM> Install-Package camljs.TypeScript.DefinitelyTyped

 

Basics

To start with, let's assume we need to fetch all Google-related letters from some mailbox list, using SharePoint Client Object Model. To generate the corresponding query using Caml Builder, you could use following javascript code:

var camlBuilder = new CamlBuilder();var caml = camlBuilder.Where()
        .TextField("Email").EqualTo("support@google.com")
        .Or()
        .TextField("Email").EqualTo("plus@google.com")
        .Or()
        .TextField("Title").BeginsWith("[Google]")
        .Or()
        .TextField("Content").Contains("Google")
        .ToString();

This will generate expected CAML:

<Where><Or><Eq><FieldRefName="Email"/><ValueType="Text">support@google.com</Value></Eq><Or><Eq><FieldRefName="Email"/><ValueType="Text">plus@google.com</Value></Eq><Or><BeginsWith><FieldRefName="Title"/><ValueType="Text">[Google]</Value></BeginsWith><Contains><FieldRefName="Content"/><ValueType="Text">Google</Value></Contains></Or></Or></Or></Where>

, which then could be used in SP.CamlQuery.

Very good so far, and have a look at some other examples!

First of all, cannot resist to mention, that CamlBuilder covers almost all Query elements, described at MSDN.

For example, seldom used Membership element:

var caml = camlBuilder.Where()
        .UserField("AssignedTo").EqualToCurrentUser()
        .Or()
        .UserField("AssignedTo").IsInCurrentUserGroups()
        .GroupBy("ProductTitle")
        .OrderBy("Priority").ThenBy("Title")
        .ToString();

This code will generate following CAML:

<Where><Or><Eq><FieldRefName="AssignedTo"/><ValueType="Integer"><UserID/></Value></Eq><MembershipType="CurrentUserGroups"><FieldRefName="AssignedTo"/></Membership></Or></Where><GroupBy><FieldRefName="ProductTitle"/></GroupBy><OrderBy><FieldRefName="Priority"/><FieldRefName="Title"/></OrderBy>

The last example at this section:

    caml = camlBuilder.Where()
        .LookupField("Category").Id().In([2, 3, 10])
        .And()
        .DateField("ExpirationDate").LessThanOrEqualTo(CamlBuilder.CamlValues.Now)
        .OrderByDesc("ExpirationDate")
        .ToString()

As you see, the code is pretty clean and readable. The resulting CAML is much more awkward, especially if you imagine it in javascript strings dress, without indentation and highlighting...

<Where><And><In><FieldRefName="Category"LookupId="True"/><Values><ValueType="Integer">2</Value><ValueType="Integer">3</Value><ValueType="Integer">10</Value></Values></In><Leq><FieldRefName="ExpirationDate"/><ValueType="Date"><Now/></Value></Leq></And></Where><OrderBy><FieldRefName="ExpirationDate"Ascending="False"/></OrderBy>

Usability

Besides of readability, CamlBuilder pretends to be very handy in development, because you can use intellisense and inline documentation:

This will help to catch a bunch of errors when writing code, and surely prevent from typos and misunderstandings, so the benefits could be really magnificient!

Contribute

Any contributions are highly appreciated!

Commented Unassigned: Unable to get property 'create' of undefined or null reference [4]

$
0
0
Hi,
I am using this tool for the first time and I am getting following error:

Unable to get property 'create' of undefined or null reference

Here is my jquery code:
var camlBuilder = new CamlBuilder();

var Query = camlBuilder.Where()
.TextField("Evidence").EqualTo("test")
.Or()
.TextField("LinkTitle").BeginsWith("1.01.")
.ToString();
Comments: I'm getting the same thing using the example from the project description: ``` var camlQuery = new CamlBuilder().Where().Any( CamlBuilder.Expression().TextField("Email").EqualTo("support@google.com"), CamlBuilder.Expression().TextField("Email").EqualTo("plus@google.com"), CamlBuilder.Expression().TextField("Title").BeginsWith("[Google]"), CamlBuilder.Expression().TextField("Content").Contains("Google") ).ToString(); ``` Chrome console error: > Uncaught TypeError: Cannot read property 'create' of undefined camljs.js:627 Builder.Finalize camljs.js:627 QueryToken.ToString camljs.js:134 (anonymous function) Am I missing something?

Commented Unassigned: Unable to get property 'create' of undefined or null reference [4]

$
0
0
Hi,
I am using this tool for the first time and I am getting following error:

Unable to get property 'create' of undefined or null reference

Here is my jquery code:
var camlBuilder = new CamlBuilder();

var Query = camlBuilder.Where()
.TextField("Evidence").EqualTo("test")
.Or()
.TextField("LinkTitle").BeginsWith("1.01.")
.ToString();
Comments: CamlJs has dependencies from SharePoint 2010/2013 javascript files. That is what causing the error. Recently I had compiled a separate file for those who want to use camljs outside in SP2007 or outside of SharePoint portals. You can find it here: https://camljs.codeplex.com/SourceControl/latest#CamlJs/camljs.spdeps.js Example of usage is in folder "sp2007orStandalone" next to this file.

Commented Unassigned: Unable to get property 'create' of undefined or null reference [4]

$
0
0
Hi,
I am using this tool for the first time and I am getting following error:

Unable to get property 'create' of undefined or null reference

Here is my jquery code:
var camlBuilder = new CamlBuilder();

var Query = camlBuilder.Where()
.TextField("Evidence").EqualTo("test")
.Or()
.TextField("LinkTitle").BeginsWith("1.01.")
.ToString();
Comments: CamlJs has some dependencies on available by default in SharePoint 2010/2013 classes Sys.StringBuilder and SP.XmlWriter. That is what causing the error: camljs tries to execute Sys.StringBuilder.create method. Recently I had compiled a separate file for those who want to use camljs in SP2007 or outside of SharePoint portals. You can find it here: https://camljs.codeplex.com/SourceControl/latest#CamlJs/camljs.spdeps.js Example of usage is in folder "sp2007orStandalone" next to this file. If you are working in SP2010 or SP2013, then you probably don't have the files deployed to the page or don't have them loaded. Please ensure that sp.js and sp.runtime.js are loaded before calling camljs.

Updated Wiki: Home

$
0
0

Project Description

Simplifies creation of SharePoint CAML queries for client-side scripts. Can be used with either SharePoint Client Object Model or SPServices.

Nuget:

PM> Install-Package CamlJs

What's new in Release 2.0

Bracket expressions and partial query generation

This is the main improvement comparing to the version 1.0, where you couldn't create complex queries because of lack of bracket expressions support.

Two new methods were added to the builder chain in order to support that: Any& All.

/** Adds And clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
All(...conditions: IExpression[]): IExpression;

 

/** Adds Or clauses to the query. Use for creating bracket-expressions in conjuction with CamlBuilder.Expression(). */
Any(...conditions: IExpression[]): IExpression;


You can use these methods in conjunction with CamlBuilder.Expression() for creating bracket expressions, for example like this:

var camlQuery = new CamlBuilder().Where().Any(
    CamlBuilder.Expression().TextField("Email").EqualTo("support@google.com"), 
    CamlBuilder.Expression().TextField("Email").EqualTo("plus@google.com"), 
    CamlBuilder.Expression().TextField("Title").BeginsWith("[Google]"), 
    CamlBuilder.Expression().TextField("Content").Contains("Google")
).ToString();


As a side effect, you can now create parts of your query separately via CamlBuilder.Expression(), and then merge them together at some point later. Also you can useCamlBuilder.Expression() for defining CAMLQuery attribute in SPServices.

Better Intellisense

Intellisense significantly improved: now different types of fields have different sets of comparison options. Field usage is made more obvious.

  1. LookupField element improved. No more misleading "casting" of lookups to the target field types: now lookup fields expose methodsId() and ValueAs<type of field>().
  2. BooleanField element added for fields of boolean type.
  3. UrlField element added for fields of type URL.
  4. DateRangesOverlap element improved. It turns out, you cannot use this element in CSOM, because CSOM ignores QueryOptions element. But you still can use DateRangesOverlap with SPServices.
  5. UserField element improved.

Migration from version 1.0 to version 2.0

None of old elements were removed, but syntax is now more strict, thus in some cases it is possible that some migration will be necessary. Please, post your problems to discussions, if you will have any.

Also, please keep in mind that some elements were marked as deprecated:

  1. LookupIdField element marked as deprecated and will be removed in the next major release. Please, useLookupField(...).Id() instead.
  2. Membership element marked as deprecated and will be removed in the next major release. Functionality ofMembership element was replaced with set of methods under UserField element.

TypeScript implementation

CamlBuilder is now implemented in TypeScript and thus can be used seamlessly by Typescript developers. Of course, you can still use JavaScript version for pure JS development.

Internally, TypeScript unit tests (tsUnit) are now used, helping to make the library much more stable. New tests are added.

Nuget

CamlBuilder is now available via Nuget.

JavaScript:

PM> Install-Package CamlJs



TypeScript definitions:

PM> Install-Package camljs.TypeScript.DefinitelyTyped

 

Basics

To start with, let's assume we need to fetch all Google-related letters from some mailbox list, using SharePoint Client Object Model. To generate the corresponding query using Caml Builder, you could use following javascript code:

var camlBuilder = new CamlBuilder();var caml = camlBuilder.Where()
        .TextField("Email").EqualTo("support@google.com")
        .Or()
        .TextField("Email").EqualTo("plus@google.com")
        .Or()
        .TextField("Title").BeginsWith("[Google]")
        .Or()
        .TextField("Content").Contains("Google")
        .ToString();

This will generate expected CAML:

<Where><Or><Eq><FieldRefName="Email"/><ValueType="Text">support@google.com</Value></Eq><Or><Eq><FieldRefName="Email"/><ValueType="Text">plus@google.com</Value></Eq><Or><BeginsWith><FieldRefName="Title"/><ValueType="Text">[Google]</Value></BeginsWith><Contains><FieldRefName="Content"/><ValueType="Text">Google</Value></Contains></Or></Or></Or></Where>

, which then could be used in SP.CamlQuery.

Very good so far, and have a look at some other examples!

First of all, cannot resist to mention, that CamlBuilder covers almost all Query elements, described at MSDN.

For example, seldom used Membership element:

var caml = camlBuilder.Where()
        .UserField("AssignedTo").EqualToCurrentUser()
        .Or()
        .UserField("AssignedTo").IsInCurrentUserGroups()
        .GroupBy("ProductTitle")
        .OrderBy("Priority").ThenBy("Title")
        .ToString();

This code will generate following CAML:

<Where><Or><Eq><FieldRefName="AssignedTo"/><ValueType="Integer"><UserID/></Value></Eq><MembershipType="CurrentUserGroups"><FieldRefName="AssignedTo"/></Membership></Or></Where><GroupBy><FieldRefName="ProductTitle"/></GroupBy><OrderBy><FieldRefName="Priority"/><FieldRefName="Title"/></OrderBy>

The last example at this section:

    caml = camlBuilder.Where()
        .LookupField("Category").Id().In([2, 3, 10])
        .And()
        .DateField("ExpirationDate").LessThanOrEqualTo(CamlBuilder.CamlValues.Now)
        .OrderByDesc("ExpirationDate")
        .ToString()

As you see, the code is pretty clean and readable. The resulting CAML is much more awkward, especially if you imagine it in javascript strings dress, without indentation and highlighting...

<Where><And><In><FieldRefName="Category"LookupId="True"/><Values><ValueType="Integer">2</Value><ValueType="Integer">3</Value><ValueType="Integer">10</Value></Values></In><Leq><FieldRefName="ExpirationDate"/><ValueType="Date"><Now/></Value></Leq></And></Where><OrderBy><FieldRefName="ExpirationDate"Ascending="False"/></OrderBy>

Usability

Besides of readability, CamlBuilder pretends to be very handy in development, because you can use intellisense and inline documentation:

This will help to catch a bunch of errors when writing code, and surely prevent from typos and misunderstandings, so the benefits could be really magnificient!

Contribute

Any contributions are highly appreciated!

New Post: Is this Tool support join between lists?

New Post: Build CAML query from Array

$
0
0
Two updates:
  1. For SP2007 and standalone, just include camljs.spdeps.js into the page before camljs.js. This file contains all the dependencies.
  2. All and Any now support the array parameter, e.g. like this:
var arrayOfExpressions = [];
arrayOfExpressions.push(CamlBuilder.Expression().TextColumn("Title").Contains("BMW"));
arrayOfExpressions.push(CamlBuilder.Expression().TextColumn("Title").Contains("Ford"));
// ...var caml = new CamlBuilder().Where().All(arrayOfExpressions);
The version that supports this syntax is available via Nuget:
Install-Package CamlJs
, or alternatively just download the latest camljs.js file.

Closed Unassigned: Unable to get property 'create' of undefined or null reference [4]

$
0
0
Hi,
I am using this tool for the first time and I am getting following error:

Unable to get property 'create' of undefined or null reference

Here is my jquery code:
var camlBuilder = new CamlBuilder();

var Query = camlBuilder.Where()
.TextField("Evidence").EqualTo("test")
.Or()
.TextField("LinkTitle").BeginsWith("1.01.")
.ToString();
Comments: Use camljs.spdefs.js if you're running SP2007 or standalone; or if you're running SP2010+, ensure that sp.runtime.js is loaded before your script is executed.
Viewing all 199 articles
Browse latest View live


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