In Dynamics client app, system administration/exceptions the subsystem is:
Line=1, Pos=13033, Xpath=/Customer/CustTable[1]/DirParty[1]
Exception is thrown during the .update command. Exception ‘Invalid entity item’ is useless.
All I need to do is update the address of an existing customer. If I can just get this working, I can most likely update any other fields needed.
Following is my code:
private static void UpdateCustomer(AxdCustomer customer)
{
string sCustID = customer.CustTable[0].AccountNum;
CustomerServiceClient csClient = new CustomerServiceClient();
CustomerService.CallContext callContext = new CustomerService.CallContext();
callContext.Company = sCompany;
AxdEntity_CustTable custTable = customer.CustTable[0];
AxdEntity_DirParty_DirOrganization dirOrg = new AxdEntity_DirParty_DirOrganization();
AxdEntity_DirPartyPostalAddressView dirAddress = new AxdEntity_DirPartyPostalAddressView();
AxdCustomer axdCustomer2 = new AxdCustomer();
axdCustomer2.ValidTimeStateType = customer.ValidTimeStateType;
axdCustomer2.ValidTimeStateTypeSpecified = true;
axdCustomer2.ValidAsOfDateTime = customer.ValidAsOfDateTime;
axdCustomer2.ValidFromDateTime = customer.ValidFromDateTime;
axdCustomer2.ValidToDateTime = customer.ValidToDateTime;
AxdEntity_CustTable custTableNew = new AxdEntity_CustTable();
custTableNew._DocumentHash = custTable._DocumentHash;
custTableNew.RecId = custTable.RecId;
custTableNew.RecVersion = custTable.RecVersion;
custTableNew.action = CustomerService.AxdEnum_AxdEntityAction.update;
custTableNew.actionSpecified = true;
/////////// update address
dirAddress.Street = CustDetails.sAddress;
dirAddress.CountryRegionId = “USA”;
/////////
custTableNew.InterCompanyDirectDelivery = CustomerService.AxdExtType_InterCompanyDirectDelivery.Yes;
custTableNew.InterCompanyDirectDeliverySpecified = true;
custTableNew.CustGroup = custTable.CustGroup;
custTableNew.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { dirOrg };
custTableNew.DirParty[0].DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { dirAddress };
axdCustomer2.CustTable = new AxdEntity_CustTable[1] { custTableNew };
try
{
csClient.update(callContext, ReadCriteria(sCustID), axdCustomer2);
Console.WriteLine(“Customer Updated!”);
}
catch (Exception e)
{
Console.WriteLine("Update Customer Failed - " + e.Message);
}
}