Is it possible to remove attachments from Emails but keep email records? [SugarCloud]

----------------

Requirement is to write a scheduler and remove the attachments on daily basis from archived emails which are linked to cases (specific status).

----------------

I was thinking to delete the note record based on email id, will it remove the attachment as well on cloud instance?

Please anyone share if there is any cloud compatible code to achieve this as a best practice and remove the attachments gracefully without deleting the email.

Thanks.

Parents
  • It's possible.

    At its most basic an Email attachment is just a Notes record related to an Email.

    The Emails bean has a field called total_attachments which tells you how many attachments are related to the Email

    So you can write a scheduler that uses SugarQuery to find all the emails with total_attachments > 0 and the specific status you want.

    Then loop through those Emails Beans  and for each one find the related notes and mark_deleted, something like:

    $link = 'notes';
    if ($emailBean->load_relationship($link)) {
        $relatedNotesBeans = $emailBean->$link->getBeans();
        foreach($relatedNotesBeans as $attachmentBean){
            $attachmentBean->mark_deleted($attachmentBean->id);
        }
    }

    This will mark those attachments (notes) as deleted = 1

    And then when the scheduler runs at the beginning of each month to clear deleted records the notes will be permanently deleted, as will the corresponding files.

    FrancescaS

Reply
  • It's possible.

    At its most basic an Email attachment is just a Notes record related to an Email.

    The Emails bean has a field called total_attachments which tells you how many attachments are related to the Email

    So you can write a scheduler that uses SugarQuery to find all the emails with total_attachments > 0 and the specific status you want.

    Then loop through those Emails Beans  and for each one find the related notes and mark_deleted, something like:

    $link = 'notes';
    if ($emailBean->load_relationship($link)) {
        $relatedNotesBeans = $emailBean->$link->getBeans();
        foreach($relatedNotesBeans as $attachmentBean){
            $attachmentBean->mark_deleted($attachmentBean->id);
        }
    }

    This will mark those attachments (notes) as deleted = 1

    And then when the scheduler runs at the beginning of each month to clear deleted records the notes will be permanently deleted, as will the corresponding files.

    FrancescaS

Children