Reputation: 694
I'm a trying to get all the appointments for a systemuser with a RetrieveMultiple method and a query expression. Example :
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);
QueryExpression qe = new QueryExpression();
qe.EntityName = "systemuser";
...
slos.RetrieveMultiple(qe);
Can I retrieve all the appointments of a systemuser (owner, organizer, required attendee, optional attendee) from a systemuser entity ?
Or do I have to retrieve all the appointments of the CRM and add conditions to know if the user is owner, organizer, required or optional attendee ?
Finally, I'm using SOAP Logger, is it the best way to generate SOAP request ?
Upvotes: 0
Views: 1287
Reputation: 694
With this Expression, I don't receive any appointments now :
QueryExpression qe = new QueryExpression
{
EntityName = "appointment",
ColumnSet = new ColumnSet("activityid", "subject", "scheduledstart", "scheduledend", "location", "description"),
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("scheduledend", ConditionOperator.GreaterThan, startTime),
new ConditionExpression("scheduledstart", ConditionOperator.LessThan, endTime)
}
},
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "activitypointer",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }),
new ConditionExpression("partyid", ConditionOperator.Equal, userResponse.UserId)
}
}
},
new LinkEntity
{
EntityAlias = "requiredattendees",
Columns = new ColumnSet(false),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activitypointer",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("participationtypemask", ConditionOperator.Equal, 5)
}
},
LinkEntities =
{
new LinkEntity
{
EntityAlias = "contact",
Columns = new ColumnSet("fullname"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "activityid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid"
},
}
}
}
};
qe.Distinct = true;
slos.RetrieveMultiple(qe);
Upvotes: 0
Reputation: 18061
You'll need to use the relationship entity activitypointer
between appointment
and systemuser
. As you'll see in my examples, this makes things a little complicated.
There are at least 2 possible ways to build your desired query:
1) As you already figured, you can filter appointments by systemuserid:
var qe = new QueryExpression
{
EntityName = "appointment",
ColumnSet = new ColumnSet("subject"),
LinkEntities =
{
new LinkEntity
{
EntityAlias = "ap",
JoinOperator = JoinOperator.Inner,
Columns = new ColumnSet(false),
LinkFromEntityName = "appointment",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("partyid", ConditionOperator.Equal, userid),
},
},
},
},
};
2) You can query the systemuser by systemuserid and add the appointments as a linked entity (like a JOIN in a sql query):
var qe2 = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet(false),
LinkEntities =
{
new LinkEntity
{
EntityAlias = "ap",
Columns = new ColumnSet(false),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "systemuser",
LinkFromAttributeName = "systemuserid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "partyid",
LinkEntities =
{
new LinkEntity
{
EntityAlias = "a",
Columns = new ColumnSet("subject"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "activityid",
LinkToEntityName = "appointment",
LinkToAttributeName = "activityid",
},
},
},
},
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.Equal, userid),
},
},
};
Concerning the filter for the participation role, you'll have to add a condition on the participationtypemask
on the activitypointer
:
// user is Organizer, Owner, required or optional Attendee
ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }),
Upvotes: 2