简体   繁体   English

CRM 2011 - 如何使用C#代码在Entity中使用子网格设置记录中的数据

[英]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);

In Response to Draiden's Comments 回应Draiden的评论

The indexer on the Entity class will automatically handle adding or updating a value. Entity类的索引器将自动处理添加或更新值。 Here is an example LinqPad program: 以下是LinqPad程序的示例:

Linqpad示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用crm sdk和C#从CRM 2011中的实体字段中获取选项集 - How to get the option set from a field in an entity in CRM 2011 using crm sdk and C# CRM v9-使用C#代码从CRM实体中删除基于ID的记录 - CRM v9 - Delete records based on ID from CRM Entity using C# Code 从Ribbon JScript CRM Online 2011调用C#代码 - Call C# Code from Ribbon JScript CRM Online 2011 在CRM 2011 C#中更新记录时避免重复 - Avoid duplicates when updating records in CRM 2011 C# 如何使用C#/ VB.Net和WCF部署服务或CRM 2011 SDK启用和禁用CRM 2011组织? - How to enable and disable a CRM 2011 Organization using C#/VB.Net and WCF Deployment Service or CRM 2011 SDK? CRM 2011如何使用Java来使用子/相关实体表单中的值更新父实体字段 - CRM 2011 how to update a Parent entity field with values from a child/related entity form using Javascript CRM 2011-C#插件 - CRM 2011 - C# PLUGIN 使用 C# 代码从 DYNAMICS 365 crm 检索/获取记录 - Retrieve/fetch records from DYNAMICS 365 crm using C# code 如何在CRM 2011中创建和删除多对多实体关系中的数据? - How to create and delete data from entity relationship many-to-many in CRM 2011? 如何从CRM 2011 IFD的OData服务中检索记录 - How to retrive records from OData service of crm 2011 IFD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM