Post

1 follower Follow
0
Avatar

REST API - Matching Condition on NULL value for Custom Field

I was able to return a list of items via REST API matching on a custom field Boolean value of 'TRUE' or 'FALSE' but I don't know how to match of its NULL value, can you please help? Below is my sample json string message to get a list of Note type items via REST API:

{

"fields": ["CreatedOn","CreatedBy","CreatedBy.Name","CreatedBy.ExternalID","CreatedBy.InternalID","Comment","PlainText","AttachedTo","EntityType","AttachedTo.Name","C_IsTWSNote"],

"orders": [

{

"fieldName": "createdOn",

"order": "Ascending"

}

],

"typeName": "Note",

"where": {

"leftExpression": {

"fieldName": "C_IsTWSNote"

},

"operator": "Equal",

"rightExpression": {

"value": "True"

},

"_type": "Compare"

}

}

Can we have more sample codes at the Clarizen REST API doc (https://success.clarizen.com/entries/57664667-Clarizen-REST-API) please?

 

Thanks.

Michael Trang Answered

Please sign in to leave a comment.

4 comments

0
Avatar

Hi Michael,

Just have "rightExpression": {"value": null}   on the compare condition. Here's a sample Json for entityQuery  POST data, testing a null Parent of a project. You may do something similar with your field.

{

"typeName": "Project",

"fields": "Name, DueDate, Parent",

"where": {

"_type": "Compare",

"leftExpression": {

"fieldName": "Parent"

},

"operator": "Equal",

"rightExpression": {

"value": null

}

}

}

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hi Ophir,

This is similar to what I used but it didn't work for me. I think this is because I am querying against a Custom Field recently created for an existing item type (in my case I use Note item type). The new Custom Field seems to be returning different value (either null or empty_value) depending on whether I am returning an existing item before the custom field is created or a new item added after the custom field is created...

For example when I was working with Note item type, I added a new Custom Field of type boolean as "IsTWSNote" (api as 'C_IsTWSNote")  and then I created a couple of new Notes via Rest API and populated it with a 'True' value for the C_IsTWSNote custom field. Then I tried to retrieve all the old Notes, which I think they will have C_IsTWSNote value of 'null' but it didn't work, here is the json post message:

 

{

"fields": ["CreatedOn","CreatedBy","CreatedBy.Name","CreatedBy.ExternalID","CreatedBy.InternalID","Comment","PlainText","AttachedTo","EntityType","AttachedTo.Name","C_IsTWSNote"],

"orders": [

{

"fieldName": "createdOn",

"order": "Ascending"

}

],

"typeName": "Note",

"where": {

"conditions": [

{

"leftExpression": {

"fieldName": "createdOn"

},

"operator": "GreaterThan",

"rightExpression": {

"value": "2014-08-05"

},

"_type": "Compare"

},

{

"leftExpression": {

"fieldName": "C_IsTWSNote"

},

"operator": "Equal",

"rightExpression": {

"value": "null"

},

"_type": "Compare"

}

],

"_type": "And"

}

}

Is this a bug on querying exiting items against a new Custom Field value = 'null'?

Michael Trang 0 votes
Comment actions Permalink
0
Avatar

I think you need to remove the quotes from "null".

Hope this helps.

Ophir

Ophir Kenig 0 votes
Comment actions Permalink