locked
Duplicate Checking using a rules engine RRS feed

  • Question

  • Hi There,

    I am currently looking at using the WF3 rules engine within a WF4 workflow.

    One of the business requirements we need to model is duplicate checking.

    I am kind of new to rules engines/workflows so you may have to bear with me.

    If I had a rule that involved finding duplicate invoices based on certain criteria how would I model that rule?

    One of my concerns is how would the rules engine process the invoices to find if the duplicate rule applied especially in the case of large numbers of invoices?

    Would I need write a custom expression?

    Cheers

    Tuesday, November 30, 2010 3:27 PM

All replies

  • Rules work by taking a single object and evaluating it against certain conditions, such as "If Price > 50 Then DiscountLevel = 10%". Rules can be made to operate over collections of data, and that is described here:

    http://msdn.microsoft.com/en-us/library/aa349356(VS.90).aspx

    I am not sure if that matches what you need; could you give a short walkthrough of the type of rule processing that you need?

    Thanks,

     Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Tuesday, November 30, 2010 10:55 PM
  • An example would be Invoice processing and in particular a requirement to check all invoices received for a customer for a duplicate on a certain match key say order type and order date.

    From what I have seen so far, you can pass into the rules engine an object which could contain a collection. That collection could be the list of previous invoices for a customer.

    As the collection is available in rules object I should be able to write rules against it,

    along the lines of(this is just pseudo code and I am making it up but hope you get the idea)

    for each PreviousOrder within the PreviousOrderCollection

    if this.currentOrderType == this.PreviousOrderCollectionCurrentItem.previousOrderType &&

    Datediff(dd, this.currentOrderDate, this.PreviousOrderCollectionCurrentItem.previousOrderDate) > 30

    Then this.IsDuplicate()

    End

    Questions I have would be,

    1. Is the approach I have suggested the correct approach?

    2. What are the guidelines when the number of previous invoices becomes large?

    3. I have had a quick look at the link you have sent using rules and I am assuming you would implement this sort of operation within its own ruleset?

    4. Are there alternatives within a Workflow to implement this behaviour?

     

     

    Wednesday, December 1, 2010 10:46 AM
  • If I was writing the application, I would use rules if the logic I wanted to use was easily modeled by an If/Else type construct and able to be expressed in declarative rules. If it was more complicated than that, then I would probably just implement that business logic in imperative code. And if it was potentially long running logic (say you had to check thousands of possible invoices for duplicates) then I would not want to perform that checking on the workflow thread, I would create a custom WorkflowRuntime service that performed the work on another thread and then signaled back to the workflow when the processing/evaluation was complete. Are these invoices in a database anywhere? if so then if it is indexed properly it should be very fast to query for a duplicate. You are using .NET 4 workflow so the easiest approach to do this sort of thing is to use an AsyncCodeActivity - here are some examples of how to create one of these to do what you need:

    http://msdn.microsoft.com/en-us/library/ee358731.aspx

    In my opinion this would probably be the way to go. Does this look like it would map to your scenario? Please provide any additional details if you still have any questions about this approach.

    Thanks,

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Wednesday, December 1, 2010 4:31 PM
  • Yes this could work in the scenario of embedding the .NET3 Rules Engine in WF4.

    Are you saying I would write some imperative code and embed in a AsyncCodeActivity or Declarative code?

    Yes the invoices are in a DB so we can look at indexing.

    We are also exploring a scenario where we host the rules engine ourselves outside of a workflow. In this scenario I can understand creating the rules to iterate a collection but if I had a large collection could I create a custom expression in imperative code?

    Thursday, December 2, 2010 10:10 AM