Skip to Content

How to get the newly created entity from backend in SAP Fiori for iOS SDK?

Hi everyone,

I am trying to get the newly created entity in the backend as a result, but I cannot find anything in the documentation. Does anyone know if this is possible or not implemented at all. The OData service responds with the newly created entity.

This is the method in question: https://help.sap.com/doc/978e4f6c968c4cc5a30f9d324aa4b1d7/Latest/en-US/Documents/Frameworks/SAPOData/Classes/OnlineODataProvider.html#/s:8SAPOData19OnlineODataProviderC12createEntityyAA0F5ValueC_AA11HTTPHeadersC7headersAA14RequestOptionsC7optionstKF

And a code sample would look something like this:


@objc func createEntity() {

        self.showFioriLoadingIndicator()

        self.view.endEditing(true)

        self.logger.info("Creating entity in backend.")

        self.zfsmobilesrvEntities.createEntity(self.entity) { error in

            self.hideFioriLoadingIndicator()

            if let error = error {

                self.logger.error("Create entry failed. Error: \(error)", error: error)

                let alertController = UIAlertController(title: NSLocalizedString("keyErrorEntityCreationTitle", value: "Create entry failed", comment: "XTIT: Title of alert message about entity creation error."), message: error.localizedDescription, preferredStyle: .alert)

                alertController.addAction(UIAlertAction(title: self.okTitle, style: .default))

                OperationQueue.main.addOperation({

                    // Present the alertController

                    self.present(alertController, animated: true)

                })

                return

            }

            self.logger.info("Create entry finished successfully.")

            OperationQueue.main.addOperation({

                self.dismiss(animated: true) {

                    FUIToastMessage.show(message: NSLocalizedString("keyEntityCreationBody", value: "Created", comment: "XMSG: Title of alert message about successful entity creation."))

                    self.tableUpdater?.entitySetHasChanged()

                }

            })

        }

    }

Basically, in the line of a successful creation of an entry, I would like to know if there is a way to also get the new entity as an object.

Thank you in advance!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 09 at 03:34 PM

    Nikola,

    This is maybe simpler than you expected - or I'm misunderstanding. If you call `createEntity(self.entity)`, the `self.entity` will be updated with the latest server version that you have after the create, i.e. all properties will be updated with the response from the create operation.

    Thanks
    Andreas

    Add comment
    10|10000 characters needed characters exceeded

    • This is exactly what I was asking. I checked and it worked :)

      Thank you!
      Nikola