@@ -83,6 +83,61 @@ void IPlugin.Execute(IServiceProvider serviceProvider)
83
83
switch ( context . MessageName )
84
84
{
85
85
case "Create" :
86
+ postStatus = entity . GetAttributeValue < OptionSetValue > ( "statuscode" ) ;
87
+ tracingService . Trace ( $ "Choice Value: { postStatus . Value } ") ;
88
+
89
+ var request = new RetrieveAttributeRequest
90
+ {
91
+ EntityLogicalName = entity . LogicalName ,
92
+ LogicalName = "statuscode" ,
93
+ RetrieveAsIfPublished = true
94
+ } ;
95
+
96
+ var response = ( RetrieveAttributeResponse ) service . Execute ( request ) ;
97
+ var attributeMetadata = ( EnumAttributeMetadata ) response . AttributeMetadata ;
98
+
99
+ var postOption = attributeMetadata . OptionSet . Options . FirstOrDefault ( opt => opt . Value == postStatus . Value ) ;
100
+ string preChoiceLabel = string . Empty ;
101
+ string postChoiceLabel = string . Empty ;
102
+ if ( postOption != null )
103
+ {
104
+ postChoiceLabel = postOption . Label . UserLocalizedLabel . Label ;
105
+ tracingService . Trace ( $ "Choice Label: { postChoiceLabel } ") ;
106
+ }
107
+ else
108
+ {
109
+ tracingService . Trace ( "Choice value not found in metadata." ) ;
110
+ }
111
+
112
+ statusHistoryRecord = new Entity ( "ccof_applicationstatushistory" ) ;
113
+ statusHistoryRecord [ "ccof_logdate" ] = DateTime . UtcNow ;
114
+ statusHistoryRecord [ "ccof_lookuptable" ] = entity . LogicalName ;
115
+ statusHistoryRecord [ "ccof_statusvalue" ] = ( int ) postStatus . Value ;
116
+ statusHistoryRecord [ "ccof_statuslabel" ] = postChoiceLabel ;
117
+ statusHistoryRecord [ "ccof_messagetype" ] = new OptionSetValue ( 100000000 ) ;
118
+ statusHistoryRecord [ "ccof_postownerid" ] = new EntityReference (
119
+ postOwner . LogicalName ,
120
+ postOwner . Id
121
+ ) ;
122
+ statusHistoryRecord [ "ccof_application" ] = new EntityReference (
123
+ "ccof_application" ,
124
+ postApp . Id
125
+ ) ;
126
+ statusHistoryRecord [ "ccof_statushistoryregardingid" ] = new EntityReference (
127
+ entity . LogicalName ,
128
+ entity . Id
129
+ ) ;
130
+ statusHistoryRecord [ "ccof_operationuser" ] = new EntityReference (
131
+ "systemuser" ,
132
+ currentUserId
133
+ ) ;
134
+ statusHistoryRecord [ "ccof_account" ] = new EntityReference (
135
+ "account" ,
136
+ account . Id
137
+ ) ;
138
+ Guid recordId = service . Create ( statusHistoryRecord ) ;
139
+ tracingService . Trace ( $ "Record created successfully with ID: { recordId } ") ;
140
+
86
141
break ;
87
142
88
143
case "Update" :
@@ -107,20 +162,20 @@ void IPlugin.Execute(IServiceProvider serviceProvider)
107
162
postStatus = entity . GetAttributeValue < OptionSetValue > ( "statuscode" ) ;
108
163
tracingService . Trace ( $ "Choice Value: { postStatus . Value } ") ;
109
164
110
- var request = new RetrieveAttributeRequest
165
+ request = new RetrieveAttributeRequest
111
166
{
112
167
EntityLogicalName = entity . LogicalName ,
113
168
LogicalName = "statuscode" ,
114
169
RetrieveAsIfPublished = true
115
170
} ;
116
171
117
- var response = ( RetrieveAttributeResponse ) service . Execute ( request ) ;
118
- var attributeMetadata = ( EnumAttributeMetadata ) response . AttributeMetadata ;
172
+ response = ( RetrieveAttributeResponse ) service . Execute ( request ) ;
173
+ attributeMetadata = ( EnumAttributeMetadata ) response . AttributeMetadata ;
119
174
120
175
var preOption = attributeMetadata . OptionSet . Options . FirstOrDefault ( opt => opt . Value == preStatus . Value ) ;
121
- var postOption = attributeMetadata . OptionSet . Options . FirstOrDefault ( opt => opt . Value == postStatus . Value ) ;
122
- string preChoiceLabel = string . Empty ;
123
- string postChoiceLabel = string . Empty ;
176
+ postOption = attributeMetadata . OptionSet . Options . FirstOrDefault ( opt => opt . Value == postStatus . Value ) ;
177
+ preChoiceLabel = string . Empty ;
178
+ postChoiceLabel = string . Empty ;
124
179
if ( preOption != null )
125
180
{
126
181
preChoiceLabel = preOption . Label . UserLocalizedLabel . Label ;
0 commit comments