我有一个方案,查找未与访问团队共享的记录。
QueryExpression query = new QueryExpression("task")
{
ColumnSet = new ColumnSet("activityid", "subject", "customid"),
Criteria = new FilterExpression()
{
Conditions =
{
new ConditionExpression("customid", ConditionOperator.NotNull)
}
},
LinkEntities =
{
new LinkEntity("task", "principalobjectaccess", "activityid", "objectid", JoinOperator.Inner)
{
Columns = new ColumnSet(true),
EntityAlias = "POA",
LinkCriteria = new FilterExpression()
{
Conditions =
{
new ConditionExpression("principaltypecode", ConditionOperator.NotEqual, "team")
}
}
}
}
};
结果包含共享和不共享的记录。
主要类型代码 值包含SystemUser或Team,在我的情况下,我希望不与任何团队共享的记录。
更新: XrmToolBox有一个插件,可以帮助我查找未共享的记录。
此插件可以回答我的问题,但是我需要一个c#代码才能执行此操作。有人知道此工具查找此类记录的机制吗?
答案 0 :(得分:0)
You do not have direct way to retrieve Records which are not shared. But what you could do is
In this way you could get list or Account/Contact (Records) which are not shared
答案 1 :(得分:0)
I checked the database and PrincipleTypeCode
is an ObjectTypeCode stored as an int
, rather than a string
.
8 is the object type code for SystemUser
9 is the object type code for Team
principaltypecode
should never equal "team", so your current query returns everything.
You might want to try:
new ConditionExpression("principaltypecode", ConditionOperator.NotEqual, 9)
答案 2 :(得分:0)
解决方案1
在Task和POA表之间进行左外部联接,仅检索acitivityId列和principaltypecode列:
public async TaskIEnumerable<glAccts> applyFilter(IEnumerable<glAccts> filterList)
{
//... code to fetch a list of all glAccts -- glUserAccess --...
var response = glUserAccess.Where(c =>
filteredGL.Any(x=>
(string.IsNullOrEmpty(x.fund) || c.fund.Contains(x.fund)) &&
(string.IsNullOrEmpty(x.location) || c.location.Contains(x.location)) &&
(string.IsNullOrEmpty(x.costCenter) || c.costCenter.Contains(x.costCenter)) &&
(string.IsNullOrEmpty(x.objects) || c.objects.Contains(x.objects))
)
);
//... rest of code
}
然后执行内存中筛选,以删除主体类型等于团队的集合中的所有条目。请注意,如果找到一个满足此条件的ID,则必须删除所有带有该ID的条目,这对于删除与用户和团队共享的任务很重要。
解决方案2
此查询将为您提供与团队共享的所有任务:
var query = new QueryExpression("task");
var principalObjectAccess = query.AddLink("principalobjectaccess", "activityid", "objectid", JoinOperator.LeftOuter);
principalObjectAccess.Columns.AddColumns("principaltypecode");
var entityCollection = _service.RetrieveMultiple(query);
运行后,您只需查询所有任务向导并减去上面查询返回的任务。您可以使用System.Linq命名空间中的Except方法轻松地做到这一点。