Reputation: 1
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 ...
I tried few ways to do that like:
(1)
private static OptionSetValue CreateOptionSet(int optionSetValue)
{
OptionSetValue optionSetInstance = new OptionSetValue();
optionSetInstance.Value = optionSetValue;
return optionSetInstance;
}
(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
Upvotes: 0
Views: 1337
Reputation: 18895
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
:
(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)
payment["zbg_paidamount"] = new OptionSetValue(400);
The indexer on the Entity class will automatically handle adding or updating a value. Here is an example LinqPad program:
Upvotes: 2