Created
December 6, 2016 22:22
-
-
Save gsherman/dfbdb2d7b382bec50e5340cc211cde4d to your computer and use it in GitHub Desktop.
Custom rule property function. Based on https://dovetailsoftware.github.io/property-extensions/
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
using System.Linq; | |
using Dovetail.SDK.Clarify; | |
using Dovetail.SDK.Properties; | |
using Dovetail.SDK.Properties.Functions; | |
using FubuCore; | |
namespace Dovetail.PropertyExtensionExamples.Functions | |
{ | |
// NumberOfOpenChildCasesOnParent | |
public class NumberOfOpenChildCasesOnParent : IPropertyFunction | |
{ | |
public static int ClosedStatus = 4; | |
public static int ClosedAdminPendingStatus = 68; | |
public string Execute(TemplateContext context, IServiceLocator services) | |
{ | |
var session = services.GetInstance<IClarifySession>(); | |
var ds = session.CreateDataSet(); | |
var parentCaseObjId = 0; | |
var childCaseGeneric = ds.CreateGenericWithFields("case", "case_victim2case"); | |
childCaseGeneric.Filter(_ => _.Equals("objid", (int)context.ObjectId)); | |
childCaseGeneric.Query(); | |
if (childCaseGeneric.Count == 1) | |
parentCaseObjId = childCaseGeneric.Rows[0].AsInt("case_victim2case"); | |
var generic = ds.CreateGenericWithFields("victimcase"); | |
generic.Filter(_ => _.Equals("supercase_objid", (int)parentCaseObjId)); | |
generic.Filter(_ => _.IsNotIn("clarify_state", ClosedStatus, ClosedAdminPendingStatus)); | |
generic.Query(); | |
return generic.DataRows().Count().ToString(); | |
} | |
} | |
// ENDSAMPLE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment