Skip to Content
0

Offline Order Creation iOS

Mar 21 at 01:06 PM

21

avatar image

Hello everyone,

I am trying to create a sales order offline (just the header of the sales order for the time being). The online part works okay.

For the offline part I've coded this:

 self.servicesOffline.open { error in
            guard error == nil else {
                return
            }
            self.isStoreOpened = true
            self.servicesOffline.download { error in
                guard error == nil else {
                    // it's offline                   
                    do {
                        let headers = HTTPHeaders()
                        //headers.setHeader( withName:"OfflineOData.RemoveAfterUpload", value:"true" )
                        self.salesOrder.orderID = 23
                        try self.servicesOffline.createEntity(self.salesOrderEntity, headers: headers)
                        FUIToastMessage.show(message: "Order Created with Success", withDuration: 3)
                        self.hideFioriLoadingIndicator()
                        return;
                    } catch let error {
                        print("an error occurred \(error)")
                        FUIToastMessage.show(message: "An error occurred: \(error) ", withDuration: 3)
                        self.hideFioriLoadingIndicator()
                        return;
                    }                  
                }

but it raises this exception at runtime:

The specified key for the new entity is a duplicate of an existing entity

This is weird because the key of the sales order entity is the orderID only and 23 is unique. I tried to assign new unique numbers but I got the same response all of the times.

Actually, I reckon I shouldn't even pass the orderID, the framework should take care of that, shouldn't it?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Andreas Schlosser Mar 21 at 03:26 PM
0

Marco,

Looks like you're mixing up things on salesOrderEntity vs salesOrder; Using self.salesOrderEntity.orderID =23 should

change what you see?

But in general you're right - not setting the PK at all should also work. The reason this doesn't work is maybe related to the parallel discussion we have on the online case where the PK 0 is always set - hope we can help you there and solve this thing at the same time.

Thanks
Andreas

Share
10 |10000 characters needed characters left characters exceeded