How can I delete child entities using end point , If I delete parent record (via end point ) in sugarcrm?
How can I delete child entities using end point , If I delete parent record (via end point ) in sugarcrm?
Hi Sagar Honrao,
It is not possible to delete all the related records via a single endpoint. For this firstly you need to get all the related records of the module via using /<module>/:record/link/:link_name GET and then need to delete all and then at the end need to delete the parent record.
Let me start by saying that I do not normally recommendation deletion of records. It is often more useful to mark them as Inactive so user can see still the history.
Depends upon your actual business use case, there are a few options but all will require coding:
1) Create a custom API end point for this.
2) Use a logic hook on the parent module that will perform the clean up on a before_delete/after_delete event.
3) Use a custom job/scheduler task to do this on a regular basis.
Romney Lai How do you mark a record as inactive? This functionality does not seem to exist any longer. I see the `deleted` column in a lot of modules, but it seems impossible to update that column value via the API.
Romney Lai How do you mark a record as inactive? This functionality does not seem to exist any longer. I see the `deleted` column in a lot of modules, but it seems impossible to update that column value via the API.
Hi Gregory Kenenitz. the simplest solution is to use a "Status" or "Type" drop down. These "inactive" records will still show up in the interface but that is okay in most situations as we often want to identify past customers for example. You can then use SugarBPM to simplify the update.
For example, if you put a Status field in Account with Active/Inactive as option, and do the same in Contacts, you can set up a SugarBPM that can update all related Contacts to Inactive when the parent Account is set to Inactive.
For current versions in the Cloud, have a look at the Data Archiver as well - - https://support.sugarcrm.com/Documentation/Sugar_Versions/11.1/Sell/Administration_Guide/System/Data_Archiver/ - which may be what you are looking for.
Thanks for the response! I saw that Archiving doc, but it isn't apparent from the doc that it applies to modules such as Accounts & Contacts. Based on what you're saying it sounds like it is.
Do you know how to do this via the API? If not, I can try doing it manually as you suggest and inspecting what API calls are made.
I have not tried this so I am not sure. However, if you look at the REST end points (/rest/v11/help) you can see /DataArchiver/:record/run endpoint which looks promising.
Good luck and I am definitely curious how you go.