What does the customer your trying to save have as a CustomerGroup? Is it "Customer" perhaps?
It seems to me like your table storing the metaenum fields might have gotten messed up.
Running this query:
SELECT * FROM [mcmd_MetaEnum] WHERE TypeName = 'ContactGroup'
Do you see a row with the "Id" column set to 1 ?
Didn't know it was you (who reported the bug). It is under review now. Was almost closed because it could be a major change. Luckily it's small enough to be included in Commerce 12.1 (likely)
It's more of a way to start a conversation ;) . We treat bugs by their severity and their impact, as well as how would the fix look like (is it too big/too risky to worth the effort). The reporter would be in the bottom of the list - well, bugs reported by external sources will be given higher priority than bugs reported by QAs (given all other criteria are the same). Bugs reported by EMVPs get a slight boost in priority as well.
For future visitors: the bug COM-6776 has been fixed in Commerce 12.1.0. Cache validation has been added for Business Foundation MetaModel, to ensure it's correctly validated when you update the models in Commerce Manager. As always we recommend to upgrade to latest version.
Thanks Quan, but is it really necessary to keep it hidden until after it is "Closed, Fixed and tested"?
Not being able to refer people on the forum to a registered bug before it is fixed and about to be released is something of a bother and hampers communication.
Not really. We tend to make the bug public as soon as possible, but that needs some cleanups - i.e. sensitive information must be removed, grammar errors and typos must be corrected. Someone (and sometimes, two people) needs to review all that, of course, so that takes time.
Go for it - I mean you can always poke support for status update and they will push us for making it public. Yes it might not sound like the best way to do thing, but our process is to do a review of work items before creating the public release (someone from development team will review technical information and someone from documentation team will review anything else). The reason: doing things in batch is always faster - less interuption and less context switch. Unless the bug is needed then we leave it there.
You can always tell support to make the bug public when you report it - btw. We will take care of such request on triage process.
EDIT: I think I can ask my team to try to make a bug public on triage if possible - if it comes from external sources.
Hi!
Is there a workaround for this? We don't have the possibility to upgrade at this moment.
Thanks!
/Kristoffer
Technically you can force a cache validation. However that is pretty risky as it's internal stuff. I will look into ir to see if there is a reasonable way to do it and get back to you
Thanks! Looks like it only happens for an old CustomerContact. If I create a new CustomerContact and use that one it works just fine.
I had a - kinda - bad news for you. The change to fix the bug Erik mentioned was to make BF depends on ISynchronizedObjectInstanceCache. It previously depended on an internal cache that you can't access.
On the brighter side - that would make a valid argument to upgrade?
Well... I will try to have them upgrade, we want to do this of course. But we have to go to 12.something, right? Upgrade to the latest version of 11 is not enough?
said bug was fixed in 12.1.0 so yes, it's recommended to upgrade to 12.1.0 at least. I would say 12.8.0 is preferred (as always, newer is better)
Hi!
So I updated to 12.8, and the problem is still there! I did an iisreset, still doesn't work. Any idea what I'm missing?
/Kristoffer
First, thumb up for the upgrade.
Second, let's take a step back here. Perhaps the bug Erik mentioned was not the bug you were seeing. Can you post the full code that you are using? It looks like you were updating CustomerGroup to some invalid values ....
Ok, so this is what we do when we get the error. It has been there for a while and is quite messy...
if (this.User.Identity.IsAuthenticated) { var isOrgAddress = false; var isNewAddress = false; var currentContact = this._customerContext.CurrentContact.CurrentContact; var customerAddress = currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId == shippingAddress.AddressId); if (customerAddress == null && _customerContext.CurrentContact.CurrentOrganization != null) { customerAddress = _customerContext.CurrentContact.CurrentOrganization.Addresses.FirstOrDefault( a => a.AddressId == shippingAddress.AddressId); isOrgAddress = customerAddress != null; } if (customerAddress == null) { customerAddress = CustomerAddress.CreateInstance(); isNewAddress = true; } this._addressBookService.MapModelToCustomerAddress(shippingAddress, customerAddress); customerAddress.AddressType = CustomerAddressTypeEnum.Shipping; if (shippingAddress.AddressId == null && !isOrgAddress) { currentContact.AddContactAddress(customerAddress); } else if (!isNewAddress) { BusinessManager.Update(customerAddress); } currentContact.SaveChanges(); }
The currentContact.SaveChanges(); triggers the error.
This code also triggers the error:
private CustomerAddress CreateOrUpdateCustomerAddress(CurrentContactFacade contact, Address address) { var customerAddress = GetAddress(contact, address.AddressId); var isNew = customerAddress == null; IEnumerable<PrimaryKeyId> existingId = contact.ContactAddresses.Select(a => a.AddressId).ToList(); if (isNew) { customerAddress = CustomerAddress.CreateInstance(); } MapModelToCustomerAddress(address, customerAddress); if (isNew) { contact.AddContactAddress(customerAddress); } else { contact.UpdateContactAddress(customerAddress); } contact.SaveChanges(); if (isNew) { customerAddress.AddressId = contact.ContactAddresses .Where(a => !existingId.Contains(a.AddressId)) .Select(a => a.AddressId) .Single(); address.AddressId = customerAddress.AddressId; } return customerAddress; }
And it is only old CustomerContacts. If I create a new CustomerContact everything works just fine so there is something with the old ones....
I don't see it being a code issue at all but a Data issue.
CustomerGroup on cls_contact in the database doesn't have a foreign key, therefore it is validated in code whenever you attempt to save a contact.
In our case it was the cache that gave a wrong result but if your error persists you might have it in the database as well.
SELECT TOP 1000 * FROM [EPiServer.Commerce].[dbo].[mcmd_MetaEnum] WHERE TypeName='ContactGroup'
Do you even have one with Id=1 there?
If you doesn't you have to create it or update all contacts with CustomerGroup=1 to something that does exists.
public void MapModelToCustomerAddress(Address address, CustomerAddress customerAddress) { customerAddress.Name = address.Organization; customerAddress.City = address.City; customerAddress.CountryCode = address.CountryCode; customerAddress.CountryName = GetAllCountries().Where(x => x.Code == address.CountryCode).Select(x => x.Name).FirstOrDefault(); customerAddress.FirstName = address.FirstName; customerAddress.LastName = address.LastName; customerAddress.Line1 = address.Line1; customerAddress.Line2 = address.Line2; customerAddress.DaytimePhoneNumber = address.DaytimePhoneNumber; customerAddress.PostalCode = address.PostalCode; customerAddress.RegionName = address.Region; // Commerce Manager expects State to be set for addresses in order management. Set it to be same as // RegionName to avoid issues. customerAddress.State = address.Region; customerAddress.Email = address.Email; customerAddress.AddressType = CustomerAddressTypeEnum.Public | (address.ShippingDefault ? CustomerAddressTypeEnum.Shipping : 0) | (address.BillingDefault ? CustomerAddressTypeEnum.Billing : 0); }
@Erik
MetaEnumId Id TypeName FriendlyName OrderId Owner AccessLevel
25 1 ContactGroup Customer 1 System 1
26 2 ContactGroup Partner 2 System 1
27 3 ContactGroup Distributor 3 System 1
32 4 ContactGroup VIP 4 System 1
Looks ok and as I said, it workd for a new CustomerContact. All old ones created before upgrading to 11.8 gives the exception.
Is the metafield also ok?
SELECT TOP 1000 * FROM [EPiServer.Commerce].[dbo].[mcmd_MetaField] WHERE Name='CustomerGroup'
It is very strange that new customers works though, they have also CustomerGroup=1? and it is still the same exception as in your first post that you are getting?
Yes, I can edit the old contacts in the Manager, but I don’t think I’ve tried to update the address and that is when it fails. I’ll try that asap!
Your code looks like it was taken from Quicksilver - so it should work. This starts to look less like a bug, but more of something with your site. I'd suggest to contact our developer support service for further assistance.
Hmm, looking at the contact object I have two(?) CustomerGroup.
One string CustomerGroup and one CustomerGroup (Mediachase.Commerce.Customer.ContactEntity) int?
Strange!? Is that correct?
Yes, it looks like you have a metafield (accidentally) added to CustomerContact class, try to look at this - perhaps remove it and try again?
Looks ok. I just found two rows in the cls_Contact table that actually for some reason has CustomerGroup = "1". And it is just these two accounts I have been testing with.
How they got the value I don't know but when I set it to NULL we are fine.
Strange, but mystery solved!
Thanks for your time and help!
That would mean that you probably never can use CustomerGroup at all.
Did you do what Quan suggested and removed the duplicated CustomerGroup from the contact?
The real one should look like in Quan's screenshot. (The Int one i think.)
No, there wasn't any double property for what I could see. It only looked like it in Visual Studio. No really sure why, but that wasn't the problem.
Hi!
After upgrade to 11.8.3 we get an exception when trying to update a customer contact.
We now get this exception:
Any ideas?
Thanks!
/Kristoffer