【问题标题】:Dynamic 365 - Unable to update related entity data in Dynamics crm from Json fileDynamic 365 - 无法从 Json 文件更新 Dynamics crm 中的相关实体数据
【发布时间】:2020-09-17 04:04:47
【问题描述】:

我的要求是根据 JSON 输入更新 Dynamics CRM 帐户实体。对于 Account 中的直接字段,我可以更新它们,但我正在努力处理相关实体。

JSON:

{
  "id": "C76B4E57-5BAC-EA11-A812-000D3AD773FF",
  "name": "3000005170",
  "description": "\"\"FISHING-TV\" LLC Support",
  "status": "Active",
  "statusReason": "Active",
  "engagedParty": {
    "id": "ae8e617a-45ac-ea11-a812-000d3ad773ff",
    "name": "\"\"FISHING-TV\" LLC",
    "@referredType": "Organization"
  },
  "agreement": [
    {
      "id": "7a94566e-73b1-ea11-a812-000d3ab958aa",
      "name": "201498-0000 <D365 UI: Contract.SES TN DB: opportunity.ses_sestn Comment: >"
    }
  ]
}

我的模型课:

public class AccountExtranet {
  public string id {
    get;
    set;
  }
  public string name {
    get;
    set;
  }
  public string description {
    get;
    set;
  }
  public string status {
    get;
    set;
  }
  public string statusReason {
    get;
    set;
  }
  public Engagedparty3 engagedParty {
    get;
    set;
  }
  public List <Agreement3> agreement {
    get;
    set;
  }
  public List <Characteristic5> characteristic {
    get;
    set;
  }
  public List <Contactmedium3> contactMedium {
    get;
    set;
  }
  public ValidforExt validFor {
    get;
    set;
  }
}

我正在更新的类文件

private static void UpdateAccount(CrmServiceClient crmclient, List <Account> allAccount, AccountExtranet extranetAccount, TraceWriter log) {
  Account account = allAccount.FirstOrDefault();
  account.Name = extranetAccount.description;
  AccountState statecode;
  bool statusExist = Enum.TryParse <AccountState> (extranetAccount ? .status, out statecode);
  if (statusExist) {
    account.StateCode = statecode;
  }
}

【问题讨论】:

  • 您好,请发布代码而不是屏幕截图。
  • 亲爱的,欢迎来到 stackoverflow。您应该编辑问题而不是将代码放在评论中。

标签: c# azure-functions dynamics-crm microsoft-dynamics dynamics-365


【解决方案1】:

虽然我们可以选择使用 web api 进行深度插入,但没有直接的方法可以在单个事务中更新所有子记录以及父记录(深度更新)。

因此您必须分别初始化每个实体对象,并设置要更新的属性值以及记录 ID (GUID) 以更新每个子记录。

var account = new Entity("account");
account.Id = new Guid("C76B4E57-5BAC-EA11-A812-000D3AD773FF");
// set attribute values
account["name"] = "3000005170";
account["description"] = "FISHING-TV LLC Support";

//Update the account
service.Update(account);

var agreement = new Entity("agreement");
agreement.Id = new Guid("7a94566e-73b1-ea11-a812-000d3ab958aa");
// set attribute values
agreement["name"] = "201498-0000 <D365 UI: Contract.SES TN DB: opportunity.ses_sestn Comment: >";

//Update the agreement 
service.Update(agreement);

【讨论】:

    猜你喜欢
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2019-02-17
    • 2018-09-22
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    相关资源
    最近更新 更多