cancel
Showing results for 
Search instead for 
Did you mean: 

Offline Order Creation iOS

marco_paciucci_danone
Participant
0 Kudos

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?

Accepted Solutions (0)

Answers (1)

Answers (1)

aschlosser
Employee
Employee
0 Kudos

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