[英]Dynamic 365 - Unable to update related entity data in Dynamics crm from Json file
我的要求是根據 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;
}
}
雖然我們可以選擇使用 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.