Skip to Content
avatar image
Former Member

Handling Odata call

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.



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 22, 2017 at 10:31 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Mar 22, 2017 at 08:14 AM

    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

    Add comment
    10|10000 characters needed characters exceeded