我需要一个给定实体的所有表单列表(multiform);我知道客户端Javascript代码的解决方案,但我使用的是服务器端代码。
我尝试使用此消息来获取实体元数据,但我无法在那里找到它:
RetrieveEntityRequest mdRequest = new RetrieveEntityRequest()
{
EntityFilters = EntityFilters.All,
LogicalName = entityName,
RetrieveAsIfPublished = false
};
我尝试检索实体FormXML,但它不存在:
private string GetFormXML(int objectTypeCode)
{
QueryExpression q = new QueryExpression("systemform");
q.ColumnSet = new ColumnSet("formxml");
q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2));
q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, objectTypeCode));
var entities = ctx.OrganizationService.RetrieveMultiple(q);
if (entities != null)
{
return entities.Entities.First().Attributes["formxml"].ToString();
}
else
{
return "";
}
}
有什么建议吗?
答案 0 :(得分:0)
我认为systemform实体将objecttypecode作为字符串,它接受实体名称而不是真实实体对象类型代码。您可以尝试将对象类型代码从数字更改为实体名称吗?
private string GetFormXML(int objectTypeCode)
{
QueryExpression q = new QueryExpression("systemform");
q.ColumnSet = new ColumnSet("formxml");
q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2));
q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, "contact"));
var entities = ctx.OrganizationService.RetrieveMultiple(q);
if (entities != null)
{
return entities.Entities.First().Attributes["formxml"].ToString();
}
else
{
return "";
}
}
答案 1 :(得分:0)
public Dictionary<Guid, string> GetNevegationItems(int objectTypeCode)
{
QueryExpression q = new QueryExpression("systemform");
q.ColumnSet = new ColumnSet("name", "formid");
q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2));
q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, objectTypeCode));
var entities = ctx.OrganizationService.RetrieveMultiple(q);
if (entities != null)
{
Dictionary<Guid, string> rslt = new Dictionary<Guid, string>();
foreach (var item in entities.Entities)
{
rslt.Add(item.GetAttributeValue<Guid>("formid"), item.GetAttributeValue<string>("name"));
}
return rslt;
}
else
{
return null;
}
}