问题描述
我在CRM中有一个场景,我需要用其增值税和注册号更新现有帐户。系统中有超过3万个帐户。我正在尝试使用CRM SDK API进行更新,但是我正在努力弄清楚如何执行实际更新。电子表格已将增值税号和注册号及其对应的编号提供给我,请注意,帐户已经存在于CRM中,因此我只需要使用其增值税号和注册号来更新正确的帐户,如何在CRM中做到这一点,请在下面的代码中提出建议:
I have a scenario in CRM where I need to update existing accounts with their Vat and Registration number. There is well over 30 thousand accounts in the system. I am trying to update using the CRM SDK API but I am battling to figure out how to perform the actual update. The vat number and reg have been provided to me in a spreadsheet with their corresponding number, please note that the accounts are already in CRM so I just need to update the correct account with its Vat and Reg number, How can I do this in CRM, please advice on my code below:
public static void UpdateAllCRMAccountsWithVATAndRegistrationNumber(IOrganizationService service)
{
QueryExpression qe = new QueryExpression();
qe.EntityName = "account";
qe.ColumnSet = new ColumnSet("account", "new_vatno", "new_registrationnumber");
qe.Criteria.AddCondition("accountnumber", ConditionOperator.In,"TA10024846", "TA10028471", "TA20014015", "TA4011652", "TA4011557");
EntityCollection response = service.RetrieveMultiple(qe);
foreach (var acc in response.Entities)
{
acc.Attributes["new_vatno"] = //this is where I am struggling to figure out how I am gong to match the records up,
acc.Attributes["new_registrationnumber"] = //this is where I am struggling to figure out how I am gong to match the records up,
service.Update(acc);
}
}
我如何将确保我更新正确的记录。我在电子表格中有帐户的增值税号和注册号,请参见下面的示例图片。请给我建议。谢谢。
How am I going to ensure that I update the correct records. I have the vat and reg numbers for the accounts in a spreadsheet, please see example image below. Can I please get advised here. Thanks.
推荐答案
由于所获取的实体的实体状态必定会失败,该状态不会为空。
Updating the fetched entity is bound to fail because of its entity state, which would not be null.
要更新所获取的实体,则需要更新实体:
To update the fetched entities, you need to new up the entity:
foreach (var acc in response.Entities)
{
var updateAccount = new Entity("account") { Id = acc.Id };
updateAccount .Attributes["new_vatno"] = null; //using null as an example.
updateAccount .Attributes["new_registrationnumber"] = null;
service.Update(acc);
}
这篇关于CRM Dynamics 2013 SDK使用2个值更新经常账户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!