Skip to Content
0

Handling Odata call

Mar 22, 2017 at 07:58 AM

86

avatar image

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.



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
G.M. Duits Mar 22, 2017 at 10:31 AM
0

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.

Show 4 Share
10 |10000 characters needed characters left characters exceeded

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

0

Hello Mahesh,

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

Kind regards,

Maarten.

0

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

1

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

0
Mahesh kumar palavalli Mar 22, 2017 at 08:14 AM
1

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

Share
10 |10000 characters needed characters left characters exceeded