Skip to Content

Offline Order Creation iOS

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: { error in
            guard error == nil else {
            self.isStoreOpened = true
   { 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)
               "Order Created with Success", withDuration: 3)
                    } catch let error {
                        print("an error occurred \(error)")
               "An error occurred: \(error) ", withDuration: 3)

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 21, 2018 at 03:26 PM


    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.


    Add comment
    10|10000 characters needed characters exceeded