首页 > 解决方案 > CRM v9 - 通过 C# 代码将数据保存在 CRM 实体中

问题描述

我创建了一个新的 CRM 实体,其中包含 2 个字段NameValue。在我的 C# 代码中,我从 Microsoft Unified Service Desk 获取相同的两个值及其名称。现在我的 C# 代码中有这些记录,现在我想将它们保存在 CRM 实体中。我现在使用下面的代码来获取值,

 string QuestionAnswer = string.Empty;

        if (dialog.QuestionControlValidate)
        {
            if (ContextParameterName != string.Empty)
            {
                var ctx = Context.GetContext();

                if (dialog.QuestionControlType == "TextBox")
                    QuestionAnswer = dialog.QuestionControlTextQuestionAnswer.ToString();
                else if (dialog.QuestionControlType == "RadioButton")
                    QuestionAnswer = dialog.QuestionControlRadioButtonSelectionAnswer.ToString();

                var updatedContext = new Context(ctx)
                {
                    [ContextParameterName] = QuestionAnswer
                };

// Code to be added here
            }

我在ContextParameterName中获取Name,在QuestionAnswer中获取Value。我想将这些记录存储在具有名称和值字段的 CRM 实体中。

标签: c#dynamics-crmcrmdynamics-crm-2016

解决方案


您在 CRM 中创建记录的代码如下所示

实体 customEntity = 新实体

 Entity abc = new Entity()
                {
                    LogicalName = "new_EntityName",
                    ["fieldName"] = ContextParameterName,
                    ["fieldValue"] = QuestionAnswer

                };
                Guid newEntityRecordGuid = CrmConn.Create(abc);

newEntityRecordGuid 将具有新创建的 Record Guid


推荐阅读