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