Error getting customer update through Aif - Error "Entity update mode must be specified"

Dear Members,

Error Message : “Entity update mode must be specified”.

I was created a customer through Customer wcf service in AX 2012, I was successfully create a customer in AX, but when customer update the above error is coming .

can yo please suggest me.

Thanks,

Srinivas.

I’m not familiar with this error. Could you please find where in code it’s thrown?

string customerName = customerEntity.FirstName + " " + customerEntity.LastName;

ICustomerDataAccess dataaccess = new CustomerDataAccess();

/// reading the existing customer details before updating

AxdCustomer customer = dataaccess.GetCustomerDetailsById(PrepareQueryCriteria(customerEntity.TargetCustomerId));

AxdEntity_CustTable custTable = customer.CustTable[0];

AxdType_DateTime dateTime = new AxdType_DateTime();

dateTime.localDateTime = DateTime.Now.ToUniversalTime();

dateTime.timezone = AxdEnum_Timezone.GMTMINUS0500INDIANA;

dateTime.Value = dateTime.localDateTime;

customer.ValidAsOfDateTime = dateTime;

customer.ValidTimeStateType = AxdEnum_AxdValidTimeStateType.Range;

customer.ValidTimeStateTypeSpecified = true;

customer.ValidToDateTime = dateTime;

customer.ValidFromDateTime = dateTime;

custTable.AccountNum = customerEntity.TargetCustomerId;

custTable.Currency = “USD”; // We need to map this one also

custTable.CustGroup = customerEntity.CustomerGroupEntity.CustomerGroup;

if (customerEntity.IsGuestCustomer)

{

custTable.OneTimeCustomer = customerEntity.IsGuestCustomer ? AxdExtType_OneTimeCustomer.Yes : AxdExtType_OneTimeCustomer.No;

custTable.OneTimeCustomerSpecified = true;

}

custTable.action = AxdEnum_AxdEntityAction.update;

custTable.actionSpecified = true;

if (custTable.DirParty[0].DirPartyContactInfoView != null)

{

custTable.DirParty[0].DirPartyContactInfoView[0].action = AxdEnum_AxdEntityAction.update;

custTable.DirParty[0].DirPartyContactInfoView[0].actionSpecified = true;

}

if (custTable.DirParty[0].DirPartyPostalAddressView != null)

{

IList<AxdEntity_DirPartyPostalAddressView> dirpostalAddress = custTable.DirParty[0].DirPartyPostalAddressView;

foreach (AxdEntity_DirPartyPostalAddressView address in dirpostalAddress)

{

address.action = AxdEnum_AxdEntityAction.update;

address.actionSpecified = true;

}

}

if (custTable.DirParty != null)

{

custTable.DirParty[0].action = AxdEnum_AxdEntityAction.update;

custTable.DirParty[0].actionSpecified = true;

}

customer.CustTable = new AxdEntity_CustTable[1] { custTable };

Update the customer through this

CustomerServiceClient proxy = new CustomerServiceClient();

proxy.update(callContext, entityKeyList, axCustomerObject);

Thanks,

Srinivasulun.

For everybody’s convenience, I’ve tried to format your code to something more readable (but it wasn’t too succesfull :)).

string customerName = customerEntity.FirstName + " " + customerEntity.LastName;
ICustomerDataAccess dataaccess = new CustomerDataAccess();

// reading the existing customer details before updating
AxdCustomer customer = dataaccess.GetCustomerDetailsById(
                                    PrepareQueryCriteria(customerEntity.TargetCustomerId));
AxdEntity_CustTable custTable = customer.CustTable[0];
AxdType_DateTime dateTime = new AxdType_DateTime();

dateTime.localDateTime = DateTime.Now.ToUniversalTime();
dateTime.timezone = AxdEnum_Timezone.GMTMINUS0500INDIANA;
dateTime.Value = dateTime.localDateTime;

customer.ValidAsOfDateTime = dateTime;
customer.ValidTimeStateType = AxdEnum_AxdValidTimeStateType.Range;
customer.ValidTimeStateTypeSpecified = true;
customer.ValidToDateTime = dateTime;
customer.ValidFromDateTime = dateTime;

custTable.AccountNum = customerEntity.TargetCustomerId;
custTable.Currency = "USD"; // We need to map this one also
custTable.CustGroup = customerEntity.CustomerGroupEntity.CustomerGroup;

if (customerEntity.IsGuestCustomer)
{
    custTable.OneTimeCustomer = customerEntity.IsGuestCustomer
        ? AxdExtType_OneTimeCustomer.Yes
        : AxdExtType_OneTimeCustomer.No;
    custTable.OneTimeCustomerSpecified = true;
}

custTable.action = AxdEnum_AxdEntityAction.update;
custTable.actionSpecified = true;

var contactInfoView =  custTable.DirParty[0].DirPartyContactInfoView;
if (contactInfoView != null)
{
    contactInfoView.action = AxdEnum_AxdEntityAction.update;
    contactInfoView.actionSpecified = true;
}

if (custTable.DirParty[0].DirPartyPostalAddressView != null)
{
    var dirpostalAddress = custTable.DirParty[0].DirPartyPostalAddressView;
    foreach (AxdEntity_DirPartyPostalAddressView address in dirpostalAddress)
    {
        address.action = AxdEnum_AxdEntityAction.update;
        address.actionSpecified = true;
    }
}

if (custTable.DirParty != null)
{
    custTable.DirParty[0].action = AxdEnum_AxdEntityAction.update;
    custTable.DirParty[0].actionSpecified = true;
}

customer.CustTable = new AxdEntity_CustTable[1] { custTable };

// Update the customer through this
CustomerServiceClient proxy = new CustomerServiceClient();
proxy.update(callContext, entityKeyList, axCustomerObject);

Could you please reduce your code to the minimal implementation that still shows the same behavior? It will tell you what’s causing the problem, which the first thing you should find by yourself, and it will make it easier for others to reproduce the problem.

One highly suspicious thing is that you’re trying to update views. Please try to remove that.

I originally thought that you would debug the service and let us know what code throws the error.

when i pass the data to service to update existing customer

CustomerServiceClient proxy = new CustomerServiceClient();
proxy.update(callContext, entityKeyList, axCustomerObject);

This is  the area i am getting the above error message.

I am getting the same error… did you discover the issue, Srinivas?

You have to set updateMode property of the entity (to a value from ValidTimeStateUpdate enum).

Hi Carrie Kroutil,

Initially we are start Integration with AX 2012 CU6, in this version we are facing the issue. Later we are update the AX 2012 CU7.In CU7 we are not face this issue. For project delivery we are temporary ignore the issue.

Hello Srinivas,

Did you resolve this issue? Can you please tell me what was the solution. I am getting the same.

Regards,
Muhammad Zeshan Khan