Upgrading to release 2.0 - UserField("ContentAudience").IsNull() no longer valid

Jan 9, 2014 at 11:35 AM
Firstly, great work on this library, it has been extremely useful.

I'm upgrading from the previous version to version 2.0.

This code worked previously:

But now it gives this error:
Object #<UserFieldExpression> has no method 'IsNull'

There is a workaround by doing Or().TextField("ContentAudience").IsNull().

The Caml I need is just <IsNull><FieldRef Name="ContentAudience" /></IsNull>, so the workaround works perfectly. However, just wondered if I'm doing something wrong, or this is expected behaviour or a small bug?

Jan 9, 2014 at 12:54 PM
Hi Bryon,

Thanks for your feedback!

CamlJs 2.0 was fully rewritten, that's why it was really a bit hard to keep track and make it 100% compatible with the version 1.0. Sorry for the inconvenience :(
In fact, I consider lack of IsNull() for the UserField as a bug, and I'm going to fix it in the next release.

But for now, I think the best solution for you will be to use the following code:
A bit of explanations:
UserField and LookupField are now Id/Value-based. I reckon the usage should be much more obvious and convenient now.

The idea can be demonstrated with a couple of examples:
var userId = //...
var caml = new CamlBuilder().Where().UserField("AssignedTo").Id().EqualTo(userId).ToString();

var caml = new CamlBuilder().Where().LookupField("Category").Id().In([1, 5, 10]).ToString();

var caml = new CamlBuilder().Where().LookupField("Country").ValueAsText().EqualTo("USA").ToString();
So instead of doing e.g. LookupIdField("...") for fetching Id of a lookup field, you do it like this: LookupField("...").Id().
And values can be of different types. For example, you can have LookupField("...").ValueAsBoolean().IsTrue() and so forth.

Hope it helps!