[英]How to add multitext values seperated by commas to optionset and lookup field in cm 2015 using c# plug-in
[英]CRM Plug-in C#, How to set lookup field according to another lookup field in post-event?
我有一个自定义实体学生,每个学生都有一个系,每个系都属于一个校园(部门和校园是查找字段)。
我想做的是创建一个新帐户并为他选择一个部门。
然后,插件根据所选部门更改校园。
这是我的代码,有人可以向我解释我需要执行哪些步骤。
var context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
Entity student = context.InputParameters["Target"] as Entity;
string Department = string.Empty;
if (student.Contains("karam_department"))
{
Department = student.GetAttributeValue<>("karam_department");
}
我建议您在创建/更新之前进行此操作,因此您可以在目标本身中设置Campus属性,这样可以避免使用另一个service.Update
。 您只需要从所选部门查询相应的校园,然后在目标实体中进行设置即可。
var context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
Entity student = context.InputParameters["Target"] as Entity;
//get the department from target
EntityReference department = student.GetAttributeValue<EntityReference>("karam_department");
if (department != null)
{
//retrieve the campus from department
Entity deptEntity = service.Retrieve("karam_department", Department.Id, new ColumnSet("karam_campus"));
//set the campus attribute in target itself
student["karam_campus"] = deptEntity.GetAttributeValue<EntityReference>("karam_campus");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.