/
boiler_code.cs
104 lines (73 loc) · 4.04 KB
/
boiler_code.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
public class Class1 : Iplugin
{
public void Execute(IServiceProvider serviceprovider)
{
//obtain the tracingservice
ITracingService tracingservice =
(ITracingService)serviceprovider.GetService(typeof(ITracingService));
//obtain the context
IPluginExecutionContext context =
(IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
//validation point for target
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && context.depth < 2)
{
Entity entity = (Entity)context.InputParameters["Target"];
IOrganizationService ServiceFactory = (IOrganizationService)serviceprovider.GetService(typeof(IOrganizationService));
IOrganizationService service = ServiceFactory.CreateOrganizationService(context.UserId);
try
{
//for sharing a case
var incidentref = new EntityReference(entity.LogicalName, entity.ID);
var userref = new EntityReference("systemuser", new Guid("76858628c4d2e911910400155d0a0438"));
var grantaccessrequest = new GrantAccessRequest
{
PrincipalAccess = new PrincipalAccess
{
AccessMask = AccessRights.ReadAccess | AccessRights.WriteAccess | AccessRights.AppendAccess | AccessRights.AppendToAccess
},
Target = incidentref
};
service.Execute(incidentref);
//optionset
//for getting the optionset
Entity status_value = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("statuscode"));
var status_info = (OptionSetValue)status_value.Attributes["statuscode"];
var status_value = status_info.Attributes["statuscode"];
int status_num = status_value.Value;
//for setting the optionset
Entity status_ref = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("statuscode"));
status_ref.Attributes["statuscode"] = new OptionSetValue(10000);
service.Update(status_ref);
//optionset
//LookupValue:
//for getting the Lookup value
Entity incidentref = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet("new_pendingat"));
if (incidentref.Contains("new_pendingat"))
{
var ownerdetails = (EntityReference)incidentref.Attributes["new_pendingat"];
var ownerstatus = service.Retrieve(ownerdetails.LogicalName, ownerdetails.Id, new ColumnSet("fullname"));
if (ownerstatus.Contains("fullname"))
{
}
}
//if ryou dont have Entity's logical Id and want to retrieve something from there
QueryByAttribute querybyexpression = new QueryByAttribute("new_joborder");
querybyexpression.AddAttributeValue("new_relatedcaseid",entity.Id);
int count = querybyexpression.Values.Count;
//
QueryByAttribute querybyexpression = new QueryByAttribute("new_joborder");
querybyexpression.AddAttributeValue("new_relatedcaseid",entity.Id);
int count = querybyexpression.Values.Count;
//
QueryByAttribute querybyexpression = new QueryByAttribute("new_joborder");
querybyexpression.AddAttributeValue("new_relatedcaseid", entity.Id);
int count = querybyexpression.Values.Count;
}
catch (Exception ex)
{
throw new Exception("" + ex.Message);
}
}
}
}