Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[SAPUI5] Get and set properties of a binded model and submit changes

Get:

1
2
3
const oModel = this.getView().getModel()
const sPath = this.getView().getBindingContext().sPath
const sID = oModel.getProperty(sPath+"/ID")

Set:

1
2
const newID = "12345"
oModel.setProperty(sPath+"/ID", newID)

When using the set property function, you can now submit your changes this way:

01
02
03
04
05
06
07
08
09
10
11
// First check if there are any changes   
if (!oModel.hasPendingChanges()) {
   MessageToast.show("Nothing to do!")
   return
}
 
// Now submit your changes
oModel.submitChanges({
  success: () => MessageToast.show("Success!"),
  error: (err) => alert(err)
})

This way is much more comfortable, than using oModel.update().