Wednesday, August 27, 2014

A Query Expression with type array being passed to a condition expression

In a conditional expression when the condition type is in you can pass an array of values. This array of values has to be properly formatted before giving in.
For an example.

query.Criteria.AddCondition(
“fieldname”,
                ConditionOperator.In,
                new object[] { "d39ecf98-3e07-e411-a3a1-00155d005107", "28c5f748-8805-e411-a3a1-00155d005107" }
                );

What if you had the values in a GUID array and if you write this in the following manner.

query.Criteria.AddCondition(
“fieldname”,
                ConditionOperator.In,
                new object[] { "d39ecf98-3e07-e411-a3a1-00155d005107", "28c5f748-8805-e411-a3a1-00155d005107" }
                );
You will be getting an error saying where Guid is expected you are giving a Guid array.

Can we sort this out without have to go through the array and create a comma separated string?
The answer is yes, we can. We can use the first written statement and then doing another change would enable us to achieve that.
link.LinkCriteria.AddCondition(new ConditionExpression(
“fieldname”,
                ConditionOperator.In,
                ids)
                );


How this is possible? The condition expression has overloads which expects an array of objects. So this allows you do this because of that. 

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...