【问题标题】:how to set/get value to the custom field of a case in MS Dynamics CRM using C#如何使用 C# 在 MS Dynamics CRM 中为案例的自定义字段设置/获取值
【发布时间】:2016-03-29 02:27:39
【问题描述】:

我有一个要求,我需要为 MS Dynamics CRM 中的每个案例提供两个联系人字段。因此,我创建了一个自定义字段“SecondaryContact”,其中包含 MS Dynamics CRM 在线案例(事件)实体的数据类型查找(联系人)。

现在我想将值(联系人 ID)从我的应用程序(在 c# 中)传递到自定义字段,并且我想根据自定义字段(联系人 ID)检索所有案例

我目前的代码是根据PrimaryContactId检索所有案例

string primaryContactId = Session["ContactId"].ToString().Trim();
var context = new ForessCRMServiceContext(FssServiceProxy.orgService);
var result = from r in context.IncidentSet where r.PrimaryContactId.Equals(primaryContactId) orderby r.CreatedOn descending select r;
foreach (Incident incident in result)
 {
   dr["TICKETID"] = incident.TicketNumber;
   dr["SUBJECT"] = incident.Title;
   dr["STATUS"] = incident.StatusCode.Value;
   dr["ROWNUMBER"] = iRowNumber;
   dr["INCIDENTID"] = incident.IncidentId;
   dt.Rows.Add(dr);

}

我正在创建这样的案例

string primaryContactId = Session["ContactId"].ToString();          
IOrganizationService _service = FssServiceProxy.orgService;
Entity incident = new Entity();
incident.LogicalName = "incident";

incident["title"] = txtSubject.Text.Trim();
incident["description"] = txtDescription.Text.Trim();
string AccountId = ConfigurationManager.AppSettings["AccountId"]==null|| ConfigurationManager.AppSettings["AccountId"].ToString().Trim().Equals("") ? "" : ConfigurationManager.AppSettings["AccountId"].ToString().Trim();
Guid customerid = new Guid(AccountId);

EntityReference CustomerId = new EntityReference("account", customerid);
incident["customerid"] = CustomerId;
Guid contactid = new Guid(primaryContactId);
EntityReference EprimaryContactId = new EntityReference("contact", contactid);
incident["primarycontactid"] = EprimaryContactId;
Guid TicketID = _service.Create(incident);

我尝试如下检索案例,但我收到错误消息“'事件'实体不包含 Name = 'SecondaryContact'的属性。”

QueryExpression query = new QueryExpression();
query.EntityName = "incident";
ColumnSet cols = new ColumnSet();
cols.AddColumns(new string[] { "ticketnumber", "title", "statecode", "incidentid", "SecondaryContact"});
query.ColumnSet = cols;
RetrieveMultipleResponse retrived = new RetrieveMultipleResponse();
RetrieveMultipleRequest retrive = new RetrieveMultipleRequest();
retrive.Query = query;
retrived = (RetrieveMultipleResponse)FssServiceProxy.orgService.Execute(retrive);
var result = retrived.Results; 

请建议我实现这一目标。 提前致谢。

【问题讨论】:

  • 我总是推荐使用 EarlyBound Entities,所以你没有任何问题(这对你来说很有趣,因为你已经混合和匹配了)你可以使用 Early Bound Generator (github.com/daryllabar/DLaB.Xrm.XrmToolBoxTools/releases ) 为您的自定义字段创建 C# 类型...

标签: c# asp.net-mvc dynamics-crm-2011


【解决方案1】:

这意味着事件实体不包含字段“SecondaryContact”。要获得此名称,您应该打开 CRM 自定义,找到事件实体,打开它,检查与 SecondaryContact 对应的字段和字段字段。

【讨论】:

    【解决方案2】:

    此行将永远无法工作:

    cols.AddColumns(new string[] { "ticketnumber", "title", "statecode", "incidentid", "SecondaryContact"});

    这是因为SecondaryContact 在 CRM 中永远不会起作用。您已经创建了一个自定义属性(根据您的问题)并且逻辑名称应该是 prefix_logicalname。当您配置新属性时,会创建此名称,可能是 new_secondarycontact 之类的名称。该逻辑名称需要在您的代码中,而不是 SecondaryContact

    【讨论】:

    • 嗨 Nicknow,我按照你提到的那样尝试过,但我仍然收到相同的错误,例如“事件”实体不包含 Name =“new_SecondaryContact”的属性。
    • CRM中属性的逻辑名称是什么?请截取显示逻辑名称的自定义屏幕的屏幕截图并将其添加到您的问题中(应该全部小写。)顺便说一句,我建议 @Daryl 使用他的早期绑定生成器的建议。它将为每个具有这些值的实体创建一个const(完全消除此问题。)
    猜你喜欢
    • 1970-01-01
    • 2020-08-22
    • 2020-03-03
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多