web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Delete Attachments from Old E-mails

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    this custom activity should work

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

  • Community Member Profile Picture
    on at

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

  • Guido Preite Profile Picture
    54,086 Moderator on at

    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
    on at

    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
    54,086 Moderator on at

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

  • Community Member Profile Picture
    on at

    I tried this one, the version 2.xx

  • Community Member Profile Picture
    on at

    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); }

               }

       }

    }

  • chrispytwist Profile Picture
    235 on at

    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.

  • Suggested answer
    StefanS365 Profile Picture
    3,575 Most Valuable Professional on at

    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
    235 on at

    [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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans