Lookup Transform - Regex for table key

I was just wondering if I can use a regex format for the key in the table of a lookUp type transform. Something that will look like this:

"type": "lookup",
"attributes": {
    "table": {
        "APMX": "inactive",
        "APM*": "active",
        "AQ*": "inactive",
        "A?L?": "active",
        "many other such conditions",
        "B*": "inactive",
        "CP*": "active",
        "CR*": "prehire",
        "default": "inactive"
    },
    "input": { 
        "type": "concat",
        "attributes": {
           "values": [
              "A_SingleCharacter_FromAnAccountAttributeTransform", 
              "A_SingleCharacter_FromAnAccountAttributeTransform",
              "A_SingleCharacter_FromAnAccountAttributeTransform",
              "A_SingleCharacter_FromAnAccountAttributeTransform"
           ]
        }
    }
}

Input to the the table is a combination of 4 characters (each character is created by reading an account attribute and assigning a letter based on the attribute value. I have not included these to avoid any confusion) and the life cycle state value should be set based on the input. However conditions are such that:
If first character is A, then check the second character and third and fourth…
But if first character is B, then LCS will be inactive without checking the following characters
Similar skip subsequent characters conditions may appear after 2nd, 3rd characters too

Hence I was thinking if there is a way to use regex for key, I could use different combinations to avoid mentioning every possible input value in the table.

Or any other possible simple solution for such a case

How large of a table?

You could always pull in the attribute data and do a substring on it and then use the Velocity Engine to evaluate a value.

{
    "name": "Lifecycle-State",
    "type": "static",
    "attributes": {
        "empStatus": {
            "type": "accountAttribute",
            "attributes": {
                "sourceName": "TST",
                "attributeName": "empStatus"
            }
        },
        "value": "#set($firstChar = $empStatus.substring(0, 1)))#if($firstChar == 'A')active#elseif($firstChar == 'B')inactive#elseif($firstChar == 'C')prehire{else}inactive#end"
    },
    "internal": false
}

We have total 4 parameters to check… and each of them has between 3-5 possible values.
So there will be possibly around close 100 combinations possible. But, for some values of certain parameters we don’t have to check any further and simply return the value (This is why I was thinking of regex option)

Hi @iam_nithesh,

Instead of using a regex expression, what if we approached it as such:

{
    "type": "lookup",
    "attributes": {
        "table": {
            "a": "active",
            "b": "inactive",
            "c": "prehire",
            "default": "inactive"
        },
        "input": {
            "attributes": {
                "input": {
                    "attributes": {
                        "input": {
                            "value": "Enter Value Here"
                        },
                        "begin": 0,
                        "end": 2
                    },
                    "type": "substring"
                }
            },
            "type": "lower"
        }
    }
}

Here, I’ve taken the first character of the value, converted it to lowercase and looked it up within the table.

Sorry I think I was not clear in my original question. I have updated it to explain better

Hi @iam_nithesh,

After reading the updated requirements, I have a solution:

{
  "attributes": {
    "table": {
        "[.]": "-",
        "[a-zA-z]": ""
    },
    "input": {
        "attributes": {
            "value": "Enter Value Here"
        },
        "type": "static"
    }
  },
  "type": "replaceAll",
  "name": "Replace All Transform"
}

The replaceAll transform can be used to pass desirable values since it accepts Regex conditions.

2 Likes

Thanks a Million @ksbagade … You are the best

I will try this as I will have to check and confirm if this transform executes replacement operation in the same order as key/value pairs are listed inside "table":{...}. I hope (and pretty sure) it does

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.