I load a purchaseOrder by using the GetPurchaseOrder() method, and I go into the lineitems, modify the property of one of the lineItems, and then run the Save() method. When I do this..it tells me I can't save because it's been modified by another user since it was loaded from the Database. I don't understand why i'm getting this error and i've looked into why it's caused and found that for some reason the LastModifiedAtLoad property is 1/1/0001 12:00 AM. Is there a reason my PurchaseOrder class isn't populating correctly
Thanks,
Dave

error trying to modify line items of PurchaseOrders
GoDaddy
Dave,
Can you provide a code snippet of how you retrieve and save the PurchaseOrder object along with the exception information
Thanks,
Colin
Ariel Mon
Sure Colin,
I have a custom "Request" class (which just represents a request for products) of which I have a property called "Order". Order is of type OrderGroup as it can be a Basket or a PurchaseOrder that I want to look at, depending if I'm looking at a past or current order. So, the get method looks kind of like this:
//gets information from a local table containing info about all Requests (RequestID happens to be a custom GUID that I'm using to identify each request)
// Orders is an aliased name and refers to CommerceContext.Current.Orders
Request myRequest = GetRequestByID(requestID)
if (request.RequestStatusCodeName == RequestStatus.WaitingForSubmission) //waiting for submission indicates to me it's a basket, so get the basketmyRequest.Order = Orders.GetBasket(request.SoldToID, request.OrderGroupID);
else //otherwise give me the Purchase Order that this representsmyRequest.Order = Orders.GetPurchaseOrder(request.SoldToID, request.OrderGroupID);
return myRequest;At this point, myRequest.Orders can be cast as a PurchaseOrder or a Basket since they both derive from OrderGroup. Everything works fine for Baskets, but for a purchaseOrder, if in my code I do something like:
((MyCustomLineItemClass)myRequest.Order.OrderForms[0].LineItems[0]).CustomStatusID = GetLineItemStatusIDByStatusCode(LineItemStatus.Cancelled);
myRequest.Order.Save();
I get an error from commerce server that says:
PurchaseOrder could not be saved because another user has modified this Order after you loaded it from storage
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: Microsoft.CommerceServer.OptimisticLockException: PurchaseOrder could not be saved because another user has modified this Order after you loaded it from storage
Source Error:
Stack Trace:
Again, the above code works fine for Baskets, I'm not quite sure what the difference is here...
What I'm doing is attempting to set the status of a line item to cancelled after it's been submitted. I have a grid that is bound to myRequest.Order.OrderForm[0].LineItems and when the user clicks the "Cancel" button, it runs the code I mention above, but it's not able to save it and bring back the grid with the new data, instead I get this error.
Thanks for your help,
Dave