Howto do process datafield comparisons without complex line rules
You may come across the requirement to compare data input in one activity against the same data input in a later "verify" activity. This need is common in data entry shops and workflow is a perfect way to handle these applications. However, entering 15 or more line rules is unweildy and memory consuming. Therefore I have created this handy class library that will allow you check your datafields against your "verify" datafields. Here's the skinny:
1) Name your DataEntry and DataVerify datafields with specific prefixes such as DataEntry... and DataVerify... within your process. An example of this would be:
- DataEntrystrFirstName
- DataVerifystrFirstName
- DataEntrystrLastName
- DataVerifystrLastName
2) Setup the Dynamic Assembly Service from BlackMarket, and setup the dll attached to this blog as a service instance within the Dynamic Assembly Service. Refer to the AD example in this blog or instructions within the Dynamic Assembly Service project for more details.
3) If you create the SmartObject manually within Visual Studio, you will need to:
- Add a property called ReturnBoolean of type Yes/No(Boolean)
- Switch to advanced mode and delete the premade smartbox methods
- Add a custom method pointing to the ServiceInstance that relates to the dll you added in step 2.
1) Use advanced mode
2) Add parameters: BPHostServer, DataEntryPrefix, DataVerifyPrefix, ProcInstID (all strings)
3) You could find this method via: K2 Object Browser > Service Object Server(s) > Service Object Server > Dynamic Assembly Service > Dynamic Assembly Service For DataEntryVerifyComparison > Methods > Class1 > DoDataComparison
4) Add a SmartObject event at the end of the activity where the succeeding lines will be dependent upon the data match/mismatch. Within the SmartObject event you would be supplying static values for your BPHostServer, the DataEntryPrefix you chose and the DataVerifyPrefix you chose. You can drag/drop the process instance > ID from the K2 Object Browser for the ProcInstID parameter value. Use a process datafield to take in the returnBoolean property of the SmartObject. You can then use the returnBoolean processdatafield in your line rules.
When the SmartObject event runs, it will execute the dll with the arguments you supplied. Based on the prefixes it will loop over all of the datafields looking for your "DataEntry" prefix. When it finds one, it will cut off the DataEntry prefix and prepend the DataVerify prefix for the comparison. Then it will compare the corresponding DataEntry and DataVerify fields' values. If they match, they will set the return value to true and move onto the next data field. If they do not match, the dll will stop looping over the datafields and will return a false to the SmartObject event.
Then of course, use the returnBoolean process datafield to base your line rules upon. If you add additional datafields, you won't have to change any code as long as you stick to your "DataEntry" and "DataVerify" prefix naming scheme.
Attachment(s): DataEntryVerifyComparison-ClassLibrary.zip