Skip to main content
January 16, 2024
Solved

How to Revert Interface to Unchanged Record When User Click Cancel?

  • January 16, 2024
  • 12 replies
  • 0 views

I have an interface that opens for a single record passed in via a rule input from a REST integration GET call. The interface opens as read-only be default. There is a button at the bottom labeled "Edit". When the user clicks this button, interface becomes editable. When the interface is editable, there is a button labeled "Cancel" at the bottom. When the user clicks the "Cancel" button, I need to discard any changes the user made, and revert back to the original copy of the record.

I have attempted to do this by calling the integration which is the GET by ID in the saveInto of the Cancel button. The value is successfully fetched, and I can view it when I put the result into a paragraph field, but when I assign this result back to the rule input, the fields of the interface are not updated and the user changes are not reverted.

Is there an easier way to discard the user changes and go back to the original record?

NOTE: The goal of the Cancel button is NOT to close the interface, but to cancel "edit mode".

    Best answer by amaans4178

    instead of calling integration again on cancel button, we can store the initial value(rule input) in a local variable, and save the initial values back in rule input on click of 'cancel' button.
    here is an example -> 

    a!localVariables(
      local!initialData: a!refreshVariable(
      value: ri!apiData,
      refreshOnReferencedVarChange: false
      ),
      local!isEditable:false,
      {
      a!textField(
        label: "Text",
        labelPosition: "ABOVE",
        saveInto: {ri!apiData},
        value: ri!apiData,
        readOnly: not(local!isEditable),
        refreshAfter: "UNFOCUS",
        validations: {}
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: "edit",
            style: "OUTLINE",
            saveInto: a!save(local!isEditable,true),
            showWhen: not(local!isEditable)
          ),
          a!buttonWidget(
            label: "caancel",
            style: "OUTLINE",
            saveInto: {a!save(local!isEditable,false),a!save(ri!apiData,local!initialData)},
            showWhen: local!isEditable
          )
        },
        align: "START",
        marginBelow: "NONE"
      )
    })
      

    12 replies

    harshitb6843
    January 16, 2024

    What you are doing is the ideal way of doing it. Let's understand why this is not working. In the designer, when you are clicking on the cancel button, can you see the older values being saved in the RI? You can see those values in the variable pane of the interface. 


    harshitb6843
    January 16, 2024

    Another way is using a local variable and saving the value of your RI in that variable. Then when you click on cancel, just save the local variable's value back to RI. 

    a!localVariables(
      local!integrationResult: ri!integrationResult,
      {}
    )

    stefanhelzle0001
    Brainy
    January 16, 2024

    I would need more details of your actual implementation to better understand what is going on.

    BTW, did you consider to keep a copy of the original data in a local variable and just go back to this on cancel?

    jayaprakashr0001
    Participating Frequently
    January 16, 2024

    Hi ryand0377,

    You are getting the data in rule input use the refreshVariable() to store the data what you got from the REST integration. When you edit you can store the details in rule input when you clicking on cancel  save the localVariable data in the rule input. The the changes you made will not be reflected in the rule input.

    amaans4178
    January 16, 2024

    instead of calling integration again on cancel button, we can store the initial value(rule input) in a local variable, and save the initial values back in rule input on click of 'cancel' button.
    here is an example -> 

    a!localVariables(
      local!initialData: a!refreshVariable(
      value: ri!apiData,
      refreshOnReferencedVarChange: false
      ),
      local!isEditable:false,
      {
      a!textField(
        label: "Text",
        labelPosition: "ABOVE",
        saveInto: {ri!apiData},
        value: ri!apiData,
        readOnly: not(local!isEditable),
        refreshAfter: "UNFOCUS",
        validations: {}
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: "edit",
            style: "OUTLINE",
            saveInto: a!save(local!isEditable,true),
            showWhen: not(local!isEditable)
          ),
          a!buttonWidget(
            label: "caancel",
            style: "OUTLINE",
            saveInto: {a!save(local!isEditable,false),a!save(ri!apiData,local!initialData)},
            showWhen: local!isEditable
          )
        },
        align: "START",
        marginBelow: "NONE"
      )
    })
      

    harshitb6843
    January 16, 2024

    This is a very good way of doing what you are trying to do. Reduces transactions, and keeps the load time low. But if there are chances that the data at the source might have changed when the user was working on that screen, then using an integration will be the right way/ 

    amaans4178
    January 17, 2024

    In such a scenario, opting for integration seems appropriate. However, ensuring a positive user experience is crucial (personal learning purpose). Users may be unaware of how the data has changed, especially if they clicked on "cancel." Should we consider displaying a banner or a similar notification to provide clarity in this situation, what will be the best way [mention:b8ea18cfbb2e4f6d841cf3c1d4d7420b:e9ed411860ed4f2ba0265705b8793d05] ?