Access record after @delete event

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rouhu
    replied
    Originally posted by Maarten
    I have a workflow that catches the @delete event. I want to be able to take an action following this event, for which I need some attributes from the deleted record. However, the record is not available anymore, and I'm getting thrown null errors in the logfile.

    Is there a way to access attributes from deleted records?
    Yes, copy the attributes to a related record in the @delete workflow actions.
    Select action Update Related Record where you have some temp fields to store values.
    description=workflow\targetEntity\attributeFetched ('id'); <-- will save the ID of the deleted record to description field of the related entity.

    Leave a comment:


  • rabii
    commented on 's reply
    i was thinking of adding functions rather then modifying existing ones. Of course if this is something you think could help improve the user experience for certain use case.

  • rabii
    commented on 's reply
    I just thought having such capacity would allow the (admins) to design a workflow that can recover info from deleted records or even have ability to restore them if they are deleted for certain reason. Adding more statuses sometimes work but sometimes it doesn't depends on what we are trying to achieve.

  • yuri
    commented on 's reply
    If we make record\findOne to return deleted records by default, it would be a breaking change. It will never happen. Adding new functions, maybe. But I wouldn't hurry with it. The system was not designed to work with deleted records at all.
    Last edited by yuri; 07-04-2023, 01:53 PM.

  • yuri
    commented on 's reply
    As I workaround, you could forbid delete access for your entity and use some statue (like 'Canceled', 'Discarded'). Then you can have a scheduled workflow that removes such record after a while if you need.

  • yuri
    replied
    Both BPM and Workflow were not designed to work with deleted target records. Moreover, the concept was that it's supposed that regular users don't have access to delete action. Better to use some status for that.

    Leave a comment:


  • rabii
    commented on 's reply
    that is weird it used to work and i have used it in different workflows/bpmn script formula. not sure but i think this could be important hence it would allow the user to access data. what about a formula like record\findDeleted() alongside with record\restoreDeleted() these will come handy which will allow the user to access deleted records when needed.

  • yuri
    replied
    It never worked.

    > most formula function has been rewritten and use a different approach.

    I don't think this is correct. I don't see any changes besides code style and some refactoring.

    Leave a comment:


  • rabii
    replied
    Hey Maarten

    You are right, this seems to be working fine in older version. i have checked it again and it is not working anymore. double checked and code for most formula function has been rewritten and use a different approach. Maybe a request to double check with the team if they want to consider this again. This could be achieve just by calling a method on the query builder like below:

    PHP Code:
    $builder->withDeleted(); 
    Issue is that this needs to be applied to most of the function. i am working now on creating an extensions that allow to interact with deleted records. i will share with you once i am done.

    Leave a comment:


  • Maarten
    replied
    Rabii, I see in the forum you make a lot of reference to this formula that should work to retrieve a deleted record:

    $travel = record\findOne('Travel', 'createdAt', 'DESC', 'id=', '64a24fea1f9d88514', 'deleted', true);

    However, it doesn't work for me. When I restore the record I can find it with:
    $travel = record\findOne('Travel', 'createdAt', 'DESC', 'id=', '64a24fea1f9d88514', 'deleted', false);

    When I delete the record, I cannot find it with:
    $travel = record\findOne('Travel', 'createdAt', 'DESC', 'id=', '64a24fea1f9d88514', 'deleted', true);

    Can someone double check that with espo v 7.5.5 this is actually working for them?

    Leave a comment:


  • rabii
    commented on 's reply
    you can't access Id of the entity that way it is by design for security reason if i remember.

  • Maarten
    commented on 's reply
    "[2023-07-03 19:52:08] ERROR: Workflow[6489e19bddfe58373]: Action failed [executeFormula] with cid [2], details: Formula: Entity required but not passed..
    "

    This is what I get when I do entity\attribute('id') in a formula script in a workflow that triggers on @delete event.

    So it seems that the deleted entity is not passed to formula scripting environment in the workflow.

    However it does seem to be accessible in a prescripted action, such as update related records

  • Maarten
    replied
    Ok, I found a workaround for now. Since in my particular case, when I delete a Travel record, I want all related Traveler records to be deleted. So now, instead of the above BPM loop, I delete all related traveler records when the Travel is deleted. Then I catch the @delete of the Traveler, and perform the API calls to delete the traveler from the sharepoint list.

    Leave a comment:


  • Maarten
    replied
    I use a BPM because my full flow is much more complex:

    Click image for larger version

Name:	image.png
Views:	411
Size:	22.2 KB
ID:	94949

    I don't think I can loop over an array of IDs in a workflow?

    I'm still unclear why I get this error in BPM. Even if I don't use any attributes of the record (as shown above), it fails.

    It seems that the workflow can access a deleted record by ID, but if that same record is used to call a BPM flow, then it fails.

    I don't think this should happen?

    Leave a comment:


  • rabii
    commented on 's reply
    why not just use a workflow instead of bpmn, i have tried it and it seems to work only one thing is that i couldn't access the deleted record attributes on the on notification but i could access attributes to update related record with data from delete record.
Working...