Post

1 follower Follow
0
Avatar

Query on project type field in c#

Need data for below query :

Select all projects with project type = Adhoc project, Planned project, Planned enhancement, Adhoc enhancement, LoB is not (PM, Horizontal, Tech-Org, Transport, Marketing).

Query in c#

EntityQuery eq = new EntityQuery

{

TypeName = "Project",

Fields = new string[] { "name", "Project.Name", "C_lob" },

Where = new And

{

Conditions =new Condition[]

{

new Compare {LeftExpression = new FieldExpression {FieldName = "ProjectType"}, Operator = Operator.In, RightExpression = new ConstantExpression {Value=new String[] {"Adhoc project", "Planned project", "Planned enhancement", "Adhoc enhancement"}}},

new Compare {LeftExpression = new FieldExpression {FieldName = "C_lob"}, Operator = Operator.NotEqual, RightExpression = new ConstantExpression {Value=new String[] {"PM", "Horizontal", "Tech-Org', 'Transport", "Marketing"}}}

}

}

};

getting error :

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://clarizen.com/api:queryExpression.

Please Help

 

Bharti Kishnani Answered

Please sign in to leave a comment.

3 comments

0
Avatar

Hi Bharti.

The In operator is to be used for sub queries. You can find several samples of this in other posts in the forum.

To test for inclusion or exclusion of several values you need to specify a Compare _condition for each, wrapped by an _Or or And condition respectively. That means you cannot use String[] (a string array) for a value in a ConstantExpression. Only a single string fits there.

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Thanks Ophir.

Can you please send me a sample query in which both Or and and both condition exist.

 

 

Bharti Kishnani 0 votes
Comment actions Permalink
0
Avatar

There you go. This one retrieves tasks that their name start with "Specific" or have their start date in Jan 2014.

EntityQuery enq = new EntityQuery

{

TypeName = "Task",

Fields = new string[] { "Name", "StartDate", "DueDate" },

Where = new Or

{

Conditions = new Condition[]

{

new Compare

{

LeftExpression=new FieldExpression {FieldName="Name"},

Operator= Operator.BeginsWith,

RightExpression=new ConstantExpression {Value="specific"}

},

new And

{

Conditions = new Condition[]

{

new Compare {LeftExpression=new FieldExpression {FieldName="StartDate"}, Operator=Operator.GreaterThan,RightExpression=new ConstantExpression {Value=new DateTime(2014,1,1)}},

new Compare {LeftExpression=new FieldExpression {FieldName="StartDate"}, Operator=Operator.LessThan,RightExpression=new ConstantExpression {Value=new DateTime(2014,2,1)}}

}

}

}

}

};

 

Hope this helps,

Ophir

Ophir Kenig 0 votes
Comment actions Permalink