CRM v9 - 通过C#代码在CRM实体中保存数据

问题描述 投票:2回答:3

我创建了一个新的CRM实体,其中包含2个名称和值字段。在我的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
            }

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

c# dynamics-crm crm dynamics-crm-2016
3个回答
0
投票

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

实体customEntity = new Entity

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

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

newEntityRecordGuid将新创建Record Guid


0
投票

我从C#代码中获取Microsoft USD的数据,然后想将其保存在CRM实体中。因为在USD中,连接是通过CRM环境自动创建的,因此我在没有明确定义连接的情况下实现了连接。

                dictionary.Add("name", new CrmDataTypeWrapper(ContextParameterName, CrmFieldType.Raw));
                dictionary.Add("value", new CrmDataTypeWrapper(QuestionAnswer, CrmFieldType.Raw));
                dictionary.Add("id", new CrmDataTypeWrapper(updatedContext["Id"], CrmFieldType.Raw));

                Guid EvntId = _client.CrmInterface.CreateNewRecord("historicaldata",dictionary,"",false,new System.Guid());

CreateNewRecord方法针对目标实体类型创建新活动


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.