[英]CRM 2011 - How to set data in records from subgrid in Entity using C# code
I am making a plugin in CRM 2011. The plugin is taking data from the Entity's subgrid by using fetchXML, making some calculate with the data and at the end of the plugin I want to set the new calculated data back in the subgrid, but I can't ... 我正在CRM 2011中创建一个插件。该插件使用fetchXML从Entity的子网格中获取数据,使用数据进行一些计算,并在插件的末尾我想在子网格中设置新的计算数据,但是我不能......
I tried few ways to do that like: 我尝试了几种方法来做到这一点:
(1) (1)
private static OptionSetValue CreateOptionSet(int optionSetValue)
{
OptionSetValue optionSetInstance = new OptionSetValue();
optionSetInstance.Value = optionSetValue;
return optionSetInstance;
}
(2) (2)
public void setVal(Entity entity, string attr, object val)
{
if (entity.Attributes.Contains(attr))
{
entity[attr] = val;
}
else
{
entity.Attributes.Add(attr, val);
}
}
and just 只是
paid["zbg_paidamount"] = 400;
payment.Attributes["zbg_suggestedamount"] = paidVal;
But nothing works... 但没有任何作用......
I am thinking maybe is from the type of the data that I am trying to set but not sure. 我想也许是我想要设置但不确定的数据类型。
Please if you can help me I am desperate. 如果你可以帮助我,我很绝望。
Thanks 谢谢
Even though it looks like you've resolved your issue each section of your code has an issue with it... 即使看起来您已经解决了问题,但代码的每个部分都存在问题......
(1) - Use the int Constructor for OptionSetValue
: (1) - 使用OptionSetValue
的int构造函数:
(2) - don't worry about checking the value existing or not, just set it directly on the entity (also don't worry about accessing the Attributes collection) (2) - 不要担心检查现有值是否存在,只需将其直接设置在实体上(也不用担心访问Attributes集合)
payment["zbg_paidamount"] = new OptionSetValue(400);
The indexer on the Entity class will automatically handle adding or updating a value. Entity类的索引器将自动处理添加或更新值。 Here is an example LinqPad program: 以下是LinqPad程序的示例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.