我创建了一个新的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实体中。
您在CRM中创建记录的代码如下所示
实体customEntity = new Entity
Entity abc = new Entity()
{
LogicalName = "new_EntityName",
["fieldName"] = ContextParameterName,
["fieldValue"] = QuestionAnswer
};
Guid newEntityRecordGuid = CrmConn.Create(abc);
newEntityRecordGuid将新创建Record Guid
我从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方法针对目标实体类型创建新活动
您可以使用Global Manager托管控件并使用CreateEntity操作。检查此链接https://docs.microsoft.com/en-us/dynamics365/customer-engagement/unified-service-desk/global-manager-hosted-control?view=dynamics-usd-4.1