[英]How to access Custom Entity fields in Dynamics 365 plugin
I have the following custom entities with the following fields: 我具有以下字段的自定义实体:
Student: 学生:
Course: 课程:
Participant (Holds a particular Student's score in a particular Course): 参与者(在特定课程中获得特定学生的分数):
I need to create a plugin which upon adding/updating a Participant's score, it updates the Participant's Student's Average accordingly. 我需要创建一个插件,该插件在添加/更新参与者的分数时,会相应地更新参与者的学生平均成绩。
So my logic is as follows: 所以我的逻辑如下:
There are a few things I'm having trouble with: 我遇到了一些麻烦:
Anyone who could give me some sample code to help with the aforementioned problems would really be helping me out. 任何可以给我一些示例代码来解决上述问题的人,都将真正帮助我。 Thanks in advance. 提前致谢。
You can do query the records in a plugin using Query Expression or FetchXML using service.RetrieveMultiple
. 您可以使用Query Expression或FetchXML使用service.RetrieveMultiple
来查询插件中的记录。 For example, you can build the fetchxml using XrmToolBox FetchXML builder or simply download the fetchxml from CRM Advanced find builder and use it in below code sample. 例如,您可以使用XrmToolBox FetchXML构建器构建 fetchxml,或者直接从CRM Advanced查找构建器下载fetchxml并在下面的代码示例中使用它。 Read more 阅读更多
var fetchXml = $@"
<fetch>
<entity name='new_particpiant'>
<attribute name='new_average'/>
<filter type='and'>
<condition attribute='new_particpiant' operator='eq' value='{GUID}'/>
</filter>
</entity>
</fetch>";
EntityCollection entities = service.RetrieveMultiple(new FetchExpression(fetchXml));
Using Query Expression : 使用查询表达式:
QueryExpression qe = new QueryExpression();
qe.EntityName = "new_particpiant";
ColumnSet columns = new ColumnSet(
new string[1]
{
"new_average",
});
ConditionExpression ce = new ConditionExpression
{
AttributeName = "new_particpiant",
Operator = ConditionOperator.Equal,
Values = { 'Your Guid' }
};
FilterExpression filterQuery = new FilterExpression();
filterQuery.FilterOperator = LogicalOperator.And;
filterQuery.AddCondition(ce);
qe.ColumnSet = columns;
EntityCollection ec = service.RetrieveMultiple(qe);
Entity data = new Entity();
if (ec.Entities.Count > 0)
{
data = ec.Entities[0];
string average = Convert.ToString(data.Attributes["new_average"]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.