Skip to content

Instantly share code, notes, and snippets.

@gsherman
Created December 6, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsherman/dfbdb2d7b382bec50e5340cc211cde4d to your computer and use it in GitHub Desktop.
Save gsherman/dfbdb2d7b382bec50e5340cc211cde4d to your computer and use it in GitHub Desktop.
Custom rule property function. Based on https://dovetailsoftware.github.io/property-extensions/
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