Question

Checking Apha Numeric ranges with an incoming code

Hi guys,

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.

Thanks in advance.

Prasan

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

Pega
November 19, 2015 - 3:39am

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

Pega
November 19, 2015 - 5:22am

Assuming your encoding scheme means that all the characters to the right of the 'T' character should be treated as a Decimal Number, then you can use the Expression:

@(Pega-RULES:String).toDecimal( @(Pega-RULES:String).substring(.StartAlpha, 1) )

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:

1.png

Running this Data Transform with your example inputs gives:

<pagedata>
    <EndNumeric>9.09</EndNumeric>
    <pxObjClass>Gcs-GCSAppli-Work</pxObjClass>
    <StartNumeric>9.00</StartNumeric>
    <StartAlpha>T09.00</StartAlpha>
    <EndAlpha>T09.09</EndAlpha>
    <pzStatus>valid</pzStatus>
</pagedata>

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'.

2.png

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.

Cheers

John

Pega
November 19, 2015 - 5:49am
Response to JOHNPW_GCS

Regarding validating the input before running the transformation - you might want to consider creating a WHEN rule something like this:

3.png

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

4.png

Testing the WHEN RULE:

5.png

6.png

Incorporating it in the Data Transform:

7.png

8.png

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.

November 20, 2015 - 11:01am
Response to JOHNPW_GCS

Hey John,

thanks for your help. I will look if I can use this scenario for my current requirement.

November 25, 2015 - 10:29am

Hi Guys,

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.

Thanks

Prasan

November 26, 2015 - 4:43am
Response to PrasannaK8545

Hi Prasan,

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.

Murali...

November 30, 2015 - 1:59pm
Response to Muralik7

Hi Murali,

My codes are similar to below.

Range: XYZ95.00-XYZ95.06

Values needs to be checked: XYZ95.04

In this case decision table will not accept the ranges in this format and will not even allow us to save the rule.

Thanks

Prasan