Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Delete Attachments from Old E-mails

Posted on by Microsoft Employee

Hi all,

I'm in a great need, I hope someone can help me out.

My organization is needing to delete the attachments from the old emails to gain some space because it is on 100% of the storage, I had a workflow that was provided by microsoft that would delete these attachments by a on demand custom workflow BUT by microsoft's grace of updating versions, this plugin is no longer useful.

we're using Dynamics 365 and I really need a new plug-in to do this job, I can find these old e-mails, but I can't delete it right now.

Anyone can help?

Thanks in advance.

*This post is locked for comments

  • chrispytwist Profile Picture
    chrispytwist 235 on at
    RE: Delete Attachments from Old E-mails

    [quote][/quote]

    Hi all,

    I'm in a great need, I hope someone can help me out.

    My organization is needing to delete the attachments from the old emails to gain some space because it is on 100% of the storage, I had a workflow that was provided by microsoft that would delete these attachments by a on demand custom workflow BUT by microsoft's grace of updating versions, this plugin is no longer useful.

    we're using Dynamics 365 and I really need a new plug-in to do this job, I can find these old e-mails, but I can't delete it right now.

    Anyone can help?

    Thanks in advance.

    Thanks for the suggestion.

    Reduce Storage Space has been rejected from the XRMToolBox Pluginkit in it's current iteration. Looks like it hasn't been updated in a year.

  • Suggested answer
    StefanS365 Profile Picture
    StefanS365 3,573 Most Valuable Professional on at
    RE: Delete Attachments from Old E-mails

    Hi Joao,

    Why not make use of the ready-to-go XrmToolBox plugin: Reduce Storage Space Usage

    See: www.xrmtoolbox.com/.../BDK.XrmToolBox.StorageSpaceCleaner

  • chrispytwist Profile Picture
    chrispytwist 235 on at
    RE: Delete Attachments from Old E-mails

    Tried the CRM Email Workflow plugin 2.3

    Showed all the prompts that it was working but the truth was revealed the next day when my storage usage ballooned to double it's size!

    System jobs showing a failure of Storage Size Statistics Collection with the note: The async operation type '20' was not recognized as a valid value for the context of: Server.

    Any help would be great.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Delete Attachments from Old E-mails

    HI, I tried to develop my own custom workflow, so I did this code, but I'm getting the same result.

    below is my code, if anyone could help me, I'd be so happy =)

    // <copyright file="WorkFlowActivityBase.cs" company="">

    // Copyright (c) 2017 All Rights Reserved

    // </copyright>

    // <author></author>

    // <date>2/3/2017 11:46:45 PM</date>

    // <summary>Implements the WorkFlowActivityBase Workflow Activity.</summary>

    // <auto-generated>

    //     This code was generated by a tool.

    //     Runtime Version:4.0.30319.1

    // </auto-generated>

    using System;

    using System.Collections.ObjectModel;

    // These namespaces are found in the Microsoft.Xrm.Sdk.dll assembly

    // found in the SDK\bin folder.

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk.Client;

    using System.Activities;

    using Microsoft.Xrm.Sdk.Workflow;

    using System.ServiceModel;

    namespace Deleta_Anexos.Deleta_Anexos

    {

       public partial class CustomWorkflow : CodeActivity

       {

           //private OrganizationServiceProxy _serviceProxy;

           [RequiredArgument]

           [Input("EMAIL")]

           [ReferenceTarget("email")]

           public InArgument<EntityReference> rEmail { get; set; }

           public sealed class LocalWorkflowContext

           {

               internal IServiceProvider ServiceProvider

               {

                   get;

                   private set;

               }

               internal IOrganizationService OrganizationService

               {

                   get;

                   private set;

               }

               internal IWorkflowContext WorkflowExecutionContext

               {

                   get;

                   private set;

               }

               internal ITracingService TracingService

               {

                   get;

                   private set;

               }

               private LocalWorkflowContext()

               {

               }

               internal LocalWorkflowContext(CodeActivityContext executionContext)

               {

                   if (executionContext == null)

                   {

                       throw new ArgumentNullException("serviceProvider");

                   }

                   // Obtain the execution context service from the service provider.

                   this.WorkflowExecutionContext = (IWorkflowContext)executionContext.GetExtension<IWorkflowContext>();

                   // Obtain the tracing service from the service provider.

                   this.TracingService = (ITracingService)executionContext.GetExtension<ITracingService>();

                   // Obtain the Organization Service factory service from the service provider

                   IOrganizationServiceFactory factory = (IOrganizationServiceFactory)executionContext.GetExtension<IOrganizationServiceFactory>();

                   // Use the factory to generate the Organization Service.

                   this.OrganizationService = factory.CreateOrganizationService(this.WorkflowExecutionContext.UserId);

               }

               internal void Trace(string message)

               {

                   if (string.IsNullOrWhiteSpace(message) || this.TracingService == null)

                   {

                       return;

                   }

                   if (this.WorkflowExecutionContext == null)

                   {

                       this.TracingService.Trace(message);

                   }

                   else

                   {

                       this.TracingService.Trace(

                           "{0}, Correlation Id: {1}, Initiating User: {2}",

                           message,

                           this.WorkflowExecutionContext.CorrelationId,

                           this.WorkflowExecutionContext.InitiatingUserId);

                   }

               }

           }

           protected override void Execute(CodeActivityContext executionContext)

           {

               try

               {

                   ITracingService tracingService = executionContext.GetExtension<ITracingService>();

                   //Create the context

                   IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

                   IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

                   IOrganizationService IOS = serviceFactory.CreateOrganizationService(context.UserId);

                   QueryExpression _attachmentQuery = new QueryExpression

                   {

                       EntityName = "activitymimeattachment",

                       ColumnSet = new ColumnSet("activitymimeattachmentid"),

                       Criteria = new FilterExpression

                       {

                           Conditions =

                           {

                               new ConditionExpression

                               {

                                   AttributeName = "activityid",

                                   Operator = ConditionOperator.Equal,

                                   Values = {rEmail.Get(executionContext).Id}

                               },

                               new ConditionExpression

                               {

                                   AttributeName = "objecttypecode",

                                   Operator = ConditionOperator.Equal,

                                   Values = { rEmail.Get(executionContext).LogicalName }

                               }

                           }

                       }

                   };

                   EntityCollection results = IOS.RetrieveMultiple(

                       _attachmentQuery);

                   for (int j = 0; j < results.TotalRecordCount; j++)

                   {

                       IOS.Delete("activitymimeattachment", results[j].Id);

                   }

               }

               catch (FaultException<OrganizationServiceFault> ex) { throw new FaultException("Erro Fault Exception: " + ex.Message); }

               catch (System.TimeoutException ex) { throw new TimeoutException("TimeOut Exception : " + ex.Message); }

               catch (Exception e) { throw new InvalidPluginExecutionException("Error occurred: " + e.Message, e); }

               }

       }

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Delete Attachments from Old E-mails

    I tried this one, the version 2.xx

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Delete Attachments from Old E-mails

    if you use the CRM 2016 version of the release it should work

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Delete Attachments from Old E-mails

    I tried to do as he said but it did not work, I believe that it lost the compatibility with Dynamics 365, = (

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Delete Attachments from Old E-mails

    you need to import the solution and create an ondemand workflow to launch against the emails,

    this post community.dynamics.com/.../55551

    stoffg reply (near the end) has all the steps

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Delete Attachments from Old E-mails

    I'm sorry, but how should I use this solution?

  • Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Delete Attachments from Old E-mails

    this custom activity should work

    github.com/.../CRM-Email-Workflow-Utilities

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans