Posted: 18 Nov 2015 14:36 EST Last activity: 30 Nov 2015 13:59 EST
Checking Apha Numeric ranges with an incoming code
I have a requirement where it we should check if a code is present in given range. Fortunately, the range happened to be an "AlphaNumeric" for which I am unable to use decision table. I tried using regular expressions but because of large code volumes we considered it as not a best practice.
Example Code: T09.00 to T09.09 (how to check the value in between this range).
Note: I can not write a decision after expanding all those codes beacuse I will end up having more than 300 codes all together.
Please suggest me a best approach to tackle this situation.
How about using a custom Rule utility function and use regular expressions in that, could not find what is not considered as best practice in that.
Another one could be use predefined functions to spilt this number and get only last two characters and then easily check if it is in the range of 0 to 09 and also check if first 4 characters are "T09." This could also be done in a custom Rule utility function
For instance, I have setup a simple Data Model consisting of 'StartAlpha', 'EndAlpha' which contains your example Text values, and 'StartNumeric' and 'EndNumeric' to hold the transformed Decimal values.
Then you can use a Data Transform (for instance) to perform the mapping:
Running this Data Transform with your example inputs gives:
So you should now be able to use 'StartNumeric' and 'EndNumeric' values in your Range Criteria in a Decision Table (although I didn't try that).
Note: you probably want to put in guard into your logic to ensure your input meets the specified criteria; so you might want to make use of some of the other functions available in the String (etc) library - for instance 'isDouble'.
You could build 'When' steps into your Data Transform to do this for instance.
And lastly - I have used 'hardcoded' two Page Properties in the example above (I'm repeating the same code for each 'Set') , but you might instead want to create a re-usable general Parameter-based DT transform here - that you can re-use the same logic for each of your inputs.
Regarding validating the input before running the transformation - you might want to consider creating a WHEN rule something like this:
A @(Pega-RULES:String).length(Param.AlphaNumeric) > 1
B @(Pega-RULES:String).substring(Param.AlphaNumeric, 0, 1) = "T"
C @(Pega-RULES:String).isDouble(@(Pega-RULES:String).substring(Param.AlphaNumeric, 1)) = true
Logic String: A AND B AND C
Testing the WHEN RULE:
Incorporating it in the Data Transform:
Note the WHEN rule has a single parameter : which is implicitly shared by the Data Transform (that is : we don't pass in an argument to the When rule, just ensure our Parameter names on the DT and WHEN are named the same).
Note : We don't log an error if the WHEN rule fails here - we just simply do not perform the mapping; this may or may not be want you need to do of course.
Also: this might be a better job done with Validation Rules ? dunno.
I have found one simple solution to the above problem.
1. I basically created an alias SQL function for an checking the codes in range for alphanumeric values and added them to "Embed-UserFunction" Class which on refresh or restarting the Pega session will appear in Calculation Builder in Report Definition.
2. I created one Data table (Data type in Pega 7.1.8) and added my alphanumeric codes as records to that entry. I only specified their start and end ranges in the table.
3. I made use of auto generated Page and Report definition for that particular data type along with my function alias created in Step 1 and retrieved the records by sending the code that is to be checked as a parameter to data page which internally sends it to its source.
4. From the results page of that respective data page i check if I have a record with this match.
This solved my Issue. Hope this post helps others in future.
Good to see that you found a solution for the problem.
Somehow I am unable to think of challenge faced in using a decision table to check if a given code is within a range of codes! Could you give me sample subset of ranges and one code that needs to be checked but it results in a failed scenario when you used decision table?
I am assuming the start and end values of a particular range follows same format i.e. if end of a range is MMK950 then its start range is MMK005 and not MMK5.