-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from delegateas/case-resolution
Resolve incident fixes
- Loading branch information
Showing
5 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
tests/SharedPluginsAndCodeactivites/IncidentDeleteAllRelatedResolutionsOnClose.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,39 @@ | ||
using DG.XrmFramework.BusinessDomain.ServiceContext; | ||
using System.Linq; | ||
|
||
namespace DG.Some.Namespace | ||
{ | ||
public class IncidentDeleteAllRelatedResolutionsOnClose : Plugin | ||
{ | ||
public IncidentDeleteAllRelatedResolutionsOnClose() : base(typeof(IncidentDeleteAllRelatedResolutionsOnClose)) | ||
{ | ||
RegisterPluginStep<Incident>( | ||
EventOperation.Update, | ||
ExecutionStage.PostOperation, | ||
ExecuteDeleteAllRelatedResolutionsOnClose) | ||
.AddFilteredAttributes(x => x.StateCode) | ||
.AddImage(ImageType.PreImage, x => x.StateCode, x => x.Title) | ||
.AddImage(ImageType.PostImage, x => x.StateCode) | ||
.SetExecutionOrder(10); | ||
} | ||
|
||
protected void ExecuteDeleteAllRelatedResolutionsOnClose(LocalPluginContext localContext) | ||
{ | ||
var preImage = localContext.PluginExecutionContext.PreEntityImages["PreImage"].ToEntity<Incident>(); | ||
if (preImage.Title != "TestRemovalOfResolutionsAfterClose") return; | ||
|
||
var postImage = localContext.PluginExecutionContext.PostEntityImages["PostImage"].ToEntity<Incident>(); | ||
|
||
if (preImage.StateCode == IncidentState.Active && postImage.StateCode != IncidentState.Active) | ||
{ | ||
using (var context = new Xrm(localContext.OrganizationService)) | ||
{ | ||
context.IncidentResolutionSet | ||
.Where(x => x.IncidentId.Id == localContext.PluginExecutionContext.PrimaryEntityId) | ||
.ToList() | ||
.ForEach(x => localContext.OrganizationAdminService.Delete(x.LogicalName, x.Id)); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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