Announcement

Collapse
No announcement yet.

Is it possible to revert last change?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to revert last change?

    Hello guys,

    yesterday I modified the formula for our entity Opportunity. However, there was a mistake in the code and a lot of opportunities have now price 0.00EUR. Is it possible to somehow revert the change? For me it would be completely fine to revert just the last change. The change is being audited in the Stream. Is it somehow possible to filter out opportunities by some change log in the stream?

    It would be really helpful for me to somehow automate this task to avoid a lot of manual work.
    Thanks a lot for the tips!Click image for larger version

Name:	image.png
Views:	182
Size:	39.8 KB
ID:	97487

  • #2
    Only idea, that comes to my mind, use a database backup of that table.

    Comment


    • #3
      Hi Jakub Grufik,

      You can try to get the previous fields values with this function in the formula script: https://docs.espocrm.com/administrat...tributefetched

      But first, test it in the Formula Sandbox.​

      Comment


      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        Hello, thank you for the tip. I already tried this and its returning 0 so function attributeFetched is keeping the original value only within that one update.

    • #4
      If changes occurred in several records, it is faster to restore the data manually, taking them from the Stream. However, if you used the Recalculate Formula for all records, then a backup is a better option.

      Comment


      • #5
        Jakub Grufik,

        There is one way to return the data that was recorded in the stream in a Update post (as in your screenshot). It will work if there were no changes recorded in the Stream later.

        You need to create a Workflow with:
        • Target Entity: Opportunity
        • Trigger Type: Manual
        Actions:

        Execute Formula Script
        Code:
        $opportunityId = workflow\targetEntity\attribute('id');
        
        $updateNoteId = record\findOne('Note', 'createdAt', 'desc', 'parentId=', $opportunityId, 'parentType=', 'Opportunity', 'type=', 'Update');​
        ​​​
        Send HTTP Request​ (you should only change URL and X-Api-Key - API key of your API user)

        Click image for larger version

Name:	image.png
Views:	258
Size:	20.4 KB
ID:	97499

        Update Target Record > Opportunity​​ (change the fields in the formula by analogy)
        Code:
        $amount = json\retrieve($_lastHttpResponseBody, 'data.attributes.was.amount');
        $closeDate = json\retrieve($_lastHttpResponseBody, 'data.attributes.was.closeDate');
        
        amount = $amount;
        closeDate = $closeDate;

        It can be converted into another type so that, for example, it works after updating a record (in this case, you can use Recalculate Formula). But first, try this option.

        Be sure to let me know if you have any problems or questions.

        Comment

        Working...
        X