cancel
Showing results for 
Search instead for 
Did you mean: 

Handling Odata call

maarten_duits2
Participant
0 Kudos

Hi,

I hope someone can help me with my SAPUI5 journey.

I have a list with an InputLisItem with a Switch.

When I toggle the Switch to True (on) a Odate.create call is made to the backend.

oModel.create(sPath, oData, { success: this._onCreatedSuccess, error: this._onCreatedFailed} );

As you can see, when an error occurs the method _onCreatedFailed will be called.

_onCreatedFailed: function(oError){  MessageBox.error("Create failed. \n\n " + "Errormessage: " + JSON.parse(oError.responseText).error.message.value ); },

The MessageBox is displayed correctly, the only issue I can't resolve now is that the switch is "on" (true) now. This is not correct, because the oData call failed. The switch state has a context binding and I think I need to re-evaluate this binding but I don't now how to trigger the re-evaluation.

Hope someone can help me.

Thanks in advance.

Kind regards,

Maarten.



Accepted Solutions (1)

Accepted Solutions (1)

maarten_duits2
Participant
0 Kudos

Hello Mahesh,

Thanks for your answer, the bind part was what I was missing. I do have a follow up question and hope you can help me with it.

The state property of the switch is bind via an Expression:

<Switch change="onSwitchChanged" state="{= ${ToSysSubscriptions}.length > 0 ? true : false }"/>

I don't know how I can re-evaluate the expression.

Thanks in advance.

Kind regards,

Maarten.

maheshpalavalli
Active Contributor
0 Kudos

where is the property: ToSysSubscriptions coming from ?(entityset)

is it from the table binding(aggregation)? and if yes, is it binded to a odata model or json model?

Best regards,
Mahesh

maarten_duits2
Participant
0 Kudos

Hello Mahesh,

ToSysSubscriptions is from an entityset which comes from an odata model.

Kind regards,

Maarten.

maheshpalavalli
Active Contributor

so you are settign the switch if there is any data in the entity set right?

if yes, you can try to do the odatamodel.refresh(true, true) after the error handle function, which will refresh the odata service

Best Regards,
Mahesh

maarten_duits2
Participant
0 Kudos

Hello Mahesh,

That is completely right. I tried your solution and it works!! I already tried the refresh method, only without the true, true options.

Thanks again!!


Kind regards,

Maarten

Answers (1)

Answers (1)

maheshpalavalli
Active Contributor

Simply access the switch instance using byId("switchID"). then call the switchInstance.setState(false); to put it to off state in the data error call.

or if the switch and list is binded to a json model then you just need to update the model.

Note: you might not be able to access "this" inside _onCreatedFailed event handler method. so add the below additional code.

error: this._onCreatedFailed.bind(this)
// let me know if you face any issues

Best Regards,

Mahesh