C# 在Dynamics CRM 2011中将发票标记为已付款
沿着……的路线 我正在尝试使用Silverlight将现有发票标记为在Dynamics CRM 2011中支付 根据,我需要做的就是设置状态代码=100001,状态代码=2 当我这样做时,我会得到一个“NotFound”异常C# 在Dynamics CRM 2011中将发票标记为已付款,c#,silverlight,dynamics-crm,dynamics-crm-2011,C#,Silverlight,Dynamics Crm,Dynamics Crm 2011,沿着……的路线 我正在尝试使用Silverlight将现有发票标记为在Dynamics CRM 2011中支付 根据,我需要做的就是设置状态代码=100001,状态代码=2 当我这样做时,我会得到一个“NotFound”异常 Guid invoiceID = new Guid("Existing Invoice Guid"); IOrganizationService orgService = OrgServiceFactory.GetInstance(); orgService.BeginR
Guid invoiceID = new Guid("Existing Invoice Guid");
IOrganizationService orgService = OrgServiceFactory.GetInstance();
orgService.BeginRetrieve("invoice", invoiceID, new ColumnSet(new string[] { "invoiceid", "statecode", "statuscode" }), (result) =>
{
var fetchResp = orgService.EndRetrieve(result);
var statecodeAttrib = fetchResp.Attributes.Single(a => a.Key == "statecode");
OptionSetValue statecode = (OptionSetValue)statecodeAttrib.Value;
statecode.Value = 2;
var statuscodeAttrib = fetchResp.Attributes.Single(a => a.Key == "statuscode");
OptionSetValue statuscode = (OptionSetValue)statuscodeAttrib.Value;
statuscode.Value = 100001;
orgService.BeginUpdate(fetchResp, (updateResult) =>
{
/* Web Exception thrown here */
orgService.EndUpdate(updateResult);
Console.Write("");
}, orgService);
}, orgService);
如果我删除“statecode”位,然后尝试将statuscode设置为2-(部分发货)或4-(账单),它将按预期工作
只有当我尝试设置这两个选项时,它才会失败。如果我只是尝试设置statuscode=100001、100002、100003(完成、部分、取消),它也会失败
是否有其他方法将发票标记为已付款?要更改记录的状态,您始终需要执行单独的设置状态请求,而不仅仅是简单地更新状态和状态代码。在您的情况下,您可以执行或请求
不幸的是,CRM 2011中的OData服务无法提供这些消息。您需要做的是通过Silverlight使用SOAP web服务。如果您想抢先一步,该库是该演练的一个很好的快速实现。执行一个标准的SetState请求也会起作用,无需建立SOAP连接
SetStateRequest request = new SetStateRequest();
request.EntityMoniker = new EntityReference(Invoice.EntityLogicalName, invoice.Id);
request.State = new OptionSetValue ((int)InvoiceState.Paid);
request.Status = new OptionSetValue (100001); // Complete
SetStateResponse response = (SetStateResponse)_service.Execute(request);
奇怪的是,我可以将状态代码设置为2或3,但不能设置其他状态。您可以使用更新将状态代码更改为处于相同状态的其他状态,但如果更改状态,则需要实际发送SetState消息。