-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
S10 set funding record status when application is approved (#47)
* etFundingRecordStatus (initial version) * Update statusReasonValue for Approved (6)
- Loading branch information
Showing
4 changed files
with
116 additions
and
406 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
OFM.Infrastructure.CustomWorkflowActivities/Application/SetFundingRecordStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using ECC.Core.DataContext; | ||
using Microsoft.Xrm.Sdk; | ||
using Microsoft.Xrm.Sdk.Messages; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using Microsoft.Xrm.Sdk.Workflow; | ||
using System; | ||
using System.Activities; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.ComTypes; | ||
using System.Threading; | ||
|
||
namespace OFM.Infrastructure.CustomWorkflowActivities.Application | ||
{ | ||
public sealed class SetFundingRecordStatus : CodeActivity | ||
{ | ||
[ReferenceTarget("ofm_application")] | ||
[RequiredArgument] | ||
[Input("Application")] | ||
public InArgument<EntityReference> application { get; set; } | ||
|
||
protected override void Execute(CodeActivityContext executionContext) | ||
{ | ||
ITracingService tracingService = executionContext.GetExtension<ITracingService>(); | ||
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); | ||
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>(); | ||
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); | ||
|
||
//var recordId = context.PrimaryEntityId; | ||
var recordId = application.Get(executionContext).Id; | ||
|
||
tracingService.Trace("{0}{1}", "Start Custom Workflow Activity: Application - SetFundingRecordStatus", DateTime.Now.ToLongTimeString()); | ||
try | ||
{ | ||
Entity applicationRcord = service.Retrieve("ofm_application", recordId, new ColumnSet("statuscode")); | ||
int statusReason = applicationRcord.GetAttributeValue<OptionSetValue>("statuscode").Value; | ||
|
||
tracingService.Trace("Checking Application record StatusReason value:{0} ", statusReason); | ||
if (applicationRcord != null && applicationRcord.Attributes.Count > 0 && statusReason == 6) // 6 - approved (application) | ||
{ | ||
tracingService.Trace("\nThe Application Record - logical name: {0}, id:{1}", applicationRcord.LogicalName, applicationRcord.Id); | ||
var fetchData = new | ||
{ | ||
ofm_application = recordId.ToString(), | ||
statecode = "0", // 0 - Active (funding) | ||
statuscode = "3" // 3 - Draft (funding) | ||
}; | ||
var fetchXml = $@"<?xml version=""1.0"" encoding=""utf-16""?> | ||
<fetch> | ||
<entity name=""ofm_funding""> | ||
<attribute name=""ofm_application"" /> | ||
<attribute name=""statecode"" /> | ||
<attribute name=""statuscode"" /> | ||
<attribute name=""ofm_version_number"" /> | ||
<filter> | ||
<condition attribute=""ofm_application"" operator=""eq"" value=""{fetchData.ofm_application}"" /> | ||
<condition attribute=""statecode"" operator=""eq"" value=""{fetchData.statecode}"" /> | ||
<condition attribute=""statuscode"" operator=""eq"" value=""{fetchData.statuscode}"" /> | ||
</filter> | ||
<order attribute=""ofm_version_number"" descending=""true"" /> | ||
</entity> | ||
</fetch>"; | ||
|
||
EntityCollection fundingRecords = service.RetrieveMultiple(new FetchExpression(fetchXml)); | ||
|
||
//Change Active Funding record status: Draft (3) --> FA Review (4) | ||
if (fundingRecords.Entities.Count > 0 && fundingRecords[0] != null) | ||
{ | ||
var id = fundingRecords[0].Id; | ||
tracingService.Trace("\nActive funding record to be updated with FA Review status: " + id); | ||
|
||
Entity fundingRecordTable = new Entity("ofm_funding"); | ||
fundingRecordTable.Id = id; | ||
fundingRecordTable["statuscode"] = new OptionSetValue(4); // 4 - FA Review (funding) | ||
service.Update(fundingRecordTable); | ||
|
||
tracingService.Trace("\nChange sucessfully active funding detail record status from Draft to FA review."); | ||
} | ||
else | ||
{ | ||
tracingService.Trace("\nNo active funding record found."); | ||
} | ||
} | ||
else | ||
{ | ||
tracingService.Trace("\nNo application record found."); | ||
} | ||
|
||
tracingService.Trace("Workflow activity end."); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
throw new InvalidWorkflowException("Exeception in Custom Workflow -" + ex.Message + ex.InnerException); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.