protected override void Execute(CodeActivityContext executionContext)
{
//Create the tracing service
try
{
//Create the context
IExecutionContext context = executionContext.GetExtension<IExecutionContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracer = executionContext.GetExtension<ITracingService>();
bool isEmailmatches = false;
EntityReference incident = EmailActivityLookup.Get(executionContext);
RetrieveRequest request = new RetrieveRequest();
request.ColumnSet = new ColumnSet(new string[] { "from", "description", "subject" });
request.Target = new EntityReference("email", incident.Id);
string email = string.Empty;
string senderqueue = string.Empty;
string senderqueueFOC = string.Empty;
bool senderqueueOutput = false;
bool senderqueueOutputFOC = false;
Guid SenderQueueId = Guid.Empty;
Entity entity = (Entity)((RetrieveResponse)service.Execute(request)).Entity;
EntityCollection IncommingParty = null;
IncommingParty = (EntityCollection)entity["from"];
for (int i = 0; i < IncommingParty.Entities.Count; i++)
{
if (IncommingParty != null && IncommingParty[i].LogicalName
== "activityparty")
{
EntityReference PartyReference =
(EntityReference)IncommingParty[i]["partyid"];
// Checking if email is sent by CRM Account
if (PartyReference.LogicalName == "systemuser")
{
// Retrieve sender Account record
Entity User = service.Retrieve("systemuser",
PartyReference.Id, new ColumnSet(true));
// wod_Account = new Entity("account");
email = User.Attributes["internalemailaddress"].ToString();
if (email.Contains("HotAlerts@QTHotAlerts.com") == true)
{
senderqueue = "Tier 1 Email";
}
if (email.Contains("ford.com") == true)
{
senderqueue = "Tier 1 Email";
}
if (email.Contains(".ca") == true)
{
senderqueueFOC = "FOC Tier 1 Email - English ";
}
if (email.Contains("icollection.com") == true)
{
senderqueue = "Tier 1 Email";
}
}
}
}
QueryByAttribute querybyattribute2 = new QueryByAttribute("queue");
querybyattribute2.ColumnSet = new ColumnSet("name", "queueid");
querybyattribute2.Attributes.AddRange("name");
// Value of queried attribute to return.
querybyattribute2.Values.AddRange(senderqueue);
EntityCollection retrieved2 = service.RetrieveMultiple(querybyattribute2);
foreach (var c in retrieved2.Entities)
// string Queueid = c.Attributes.Contains("queueid").ToString();
{
SenderQueueId = c.GetAttributeValue<System.Guid>("queueid");
}
if (senderqueue != null && senderqueue != string.Empty)
{
senderqueueOutput = true;
}
if (senderqueueFOC != null && senderqueueFOC != string.Empty)
{
senderqueueOutputFOC = true;
}
this.OutSenderSearchFOC.Set(executionContext, senderqueueOutputFOC);
this.OutSenderSearch.Set(executionContext, senderqueueOutput);
}
catch (Exception ex)
{
Helpers.Throw(String.Format("An error occurred in the {0} Workflow.",
this.GetType().ToString()),
ex);
}
}
[ReferenceTarget("email")]
[Input("EmailActivity")]
public InArgument<EntityReference> EmailActivityLookup { get; set; }
[Output("OutSenderSearch")]
public OutArgument<bool> OutSenderSearch { get; set; }
[Output("OutSenderSearchFOC")]
public OutArgument<bool> OutSenderSearchFOC { get; set; }
}
}
{
//Create the tracing service
try
{
//Create the context
IExecutionContext context = executionContext.GetExtension<IExecutionContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracer = executionContext.GetExtension<ITracingService>();
bool isEmailmatches = false;
EntityReference incident = EmailActivityLookup.Get(executionContext);
RetrieveRequest request = new RetrieveRequest();
request.ColumnSet = new ColumnSet(new string[] { "from", "description", "subject" });
request.Target = new EntityReference("email", incident.Id);
string email = string.Empty;
string senderqueue = string.Empty;
string senderqueueFOC = string.Empty;
bool senderqueueOutput = false;
bool senderqueueOutputFOC = false;
Guid SenderQueueId = Guid.Empty;
Entity entity = (Entity)((RetrieveResponse)service.Execute(request)).Entity;
EntityCollection IncommingParty = null;
IncommingParty = (EntityCollection)entity["from"];
for (int i = 0; i < IncommingParty.Entities.Count; i++)
{
if (IncommingParty != null && IncommingParty[i].LogicalName
== "activityparty")
{
EntityReference PartyReference =
(EntityReference)IncommingParty[i]["partyid"];
// Checking if email is sent by CRM Account
if (PartyReference.LogicalName == "systemuser")
{
// Retrieve sender Account record
Entity User = service.Retrieve("systemuser",
PartyReference.Id, new ColumnSet(true));
// wod_Account = new Entity("account");
email = User.Attributes["internalemailaddress"].ToString();
if (email.Contains("HotAlerts@QTHotAlerts.com") == true)
{
senderqueue = "Tier 1 Email";
}
if (email.Contains("ford.com") == true)
{
senderqueue = "Tier 1 Email";
}
if (email.Contains(".ca") == true)
{
senderqueueFOC = "FOC Tier 1 Email - English ";
}
if (email.Contains("icollection.com") == true)
{
senderqueue = "Tier 1 Email";
}
}
}
}
QueryByAttribute querybyattribute2 = new QueryByAttribute("queue");
querybyattribute2.ColumnSet = new ColumnSet("name", "queueid");
querybyattribute2.Attributes.AddRange("name");
// Value of queried attribute to return.
querybyattribute2.Values.AddRange(senderqueue);
EntityCollection retrieved2 = service.RetrieveMultiple(querybyattribute2);
foreach (var c in retrieved2.Entities)
// string Queueid = c.Attributes.Contains("queueid").ToString();
{
SenderQueueId = c.GetAttributeValue<System.Guid>("queueid");
}
if (senderqueue != null && senderqueue != string.Empty)
{
senderqueueOutput = true;
}
if (senderqueueFOC != null && senderqueueFOC != string.Empty)
{
senderqueueOutputFOC = true;
}
this.OutSenderSearchFOC.Set(executionContext, senderqueueOutputFOC);
this.OutSenderSearch.Set(executionContext, senderqueueOutput);
}
catch (Exception ex)
{
Helpers.Throw(String.Format("An error occurred in the {0} Workflow.",
this.GetType().ToString()),
ex);
}
}
[ReferenceTarget("email")]
[Input("EmailActivity")]
public InArgument<EntityReference> EmailActivityLookup { get; set; }
[Output("OutSenderSearch")]
public OutArgument<bool> OutSenderSearch { get; set; }
[Output("OutSenderSearchFOC")]
public OutArgument<bool> OutSenderSearchFOC { get; set; }
}
}
No comments:
Post a Comment