-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteAnnotation.cs
59 lines (56 loc) · 2.63 KB
/
DeleteAnnotation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
namespace LinkDev.DeleteAnnotation
{
public class DeleteAnnotation : CodeActivity
{
/// <summary>
/// Custome Activity to Delete Annotation from Dynamics CRM after upload it to Azure Blob Storage
/// </summary>
///<Author>Ossama Abdallah</Author>
/// <param name="executionContext"></param>
protected override void Execute(CodeActivityContext executionContext)
{
try
{
// Get the context service.
var context = executionContext.GetExtension<IWorkflowContext>();
var serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
// Use the context service to create an instance of IOrganizationService.
IOrganizationService orgService = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
if ((context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity))
{
Entity noteEntity = (Entity)context.InputParameters["Target"];
EntityReference ObjectEntity = ((EntityReference)noteEntity.Attributes["objectid"]);
string EntityCollectionXML = "<fetch version='1.0' output-format='xml-platform' no-lock='true' mapping='logical' distinct='true'>" +
" <entity name='ldv_blobstorageentity'> " +
" <attribute name='ldv_name' /> " +
" </entity>" +
"</fetch>";
EntityCollection Entitiesvalues = orgService.RetrieveMultiple(new FetchExpression(EntityCollectionXML));
if (Entitiesvalues.Entities != null && Entitiesvalues.Entities.Count > 0)
{
foreach (var item in Entitiesvalues.Entities)
{
if (item.Attributes["ldv_name"].ToString() == ObjectEntity.LogicalName)
{
orgService.Delete(noteEntity.LogicalName, noteEntity.Id);
}
}
}
}
}
catch (Exception exc)
{
throw new InvalidPluginExecutionException("Custom Step: " + exc.Message);
}
}
}
}