Reverse attribute value and extract part of the string

HI team

I have a requirement where attribute value has to be reversed and extract part of the string.

Reverse value transform is not present as out of the box functionality.

This is key value pair separated by colon(:slight_smile: and each value is separated by ~. Basically this is org hierarchy and wanted to fetch value extract 3rd occurrence of ~
i.e. GH.

For example:

Attribute value: 50002768:QR~50004950:OP~50004747:MN~50004663:KL~50002866:IJ~50001031:GH~50001034:EF~50001030:CD~50001029:AB

Output: GH (After value reverse)

Hi @mabhavsa

For this i think you will have to make use of velocity template language in static transform. You can read the attribute value and pass it as an input to static transform and then in “value” key, you can try to write the VTL code to reverse the string and then use substring transform to extract the require value.

I would advice to use the account attribute instead of using the identity attribute value, because by seeing example input in the question, there could be challenges in storing such a long value in another identity attribute due to the length constraints on identity attributes.

Please let me know if you have any issues in implementing it.

Thank You
Regards
Vikas.

Hello @mabhavsa,

Here a transform for reversing a string :

{
    "name": "test-reserved-string",
    "type": "static",
    "attributes": {
        "value": "#set($input = '50002768:QR~50004950:OP~50004747:MN~50004663:KL~50002866:IJ~50001031:GH~50001034:EF~50001030:CD~50001029:AB') #set($reversedInput = '') #set($length = $input.length()) #set($i = $length - 1)#foreach($dummy in [1..$length]) #set($i = $foreach.count - 1) #set($reversedInput = $input.charAt($i)+$reversedInput)#end$reversedInput"
    },
    "internal": false
}

This is a test with static value.

If you can adapt the transform in your use case for retreving an identity attribute or account attribute.

Example if i want to retrived the based on identityAttribute :

{
    "name": "test-reserved-string",
    "type": "static",
    "attributes": {
        "myAttValue": {
            "type": "identityAttribute",
            "attributes": {
                "name": "myIdentityAttName"
            }
        },
        "value": "#set($input = $myIdentityAttValue ) #set($reversedInput = '') #set($length = $input.length()) #set($i = $length - 1)#foreach($dummy in [1..$length]) #set($i = $foreach.count - 1) #set($reversedInput = $input.charAt($i)+$reversedInput)#end$reversedInput"
    },
    "internal": false
}

You must replaced myIdentityAttName by your identity attribute name or adapt your input (myAttValue) recuperation.

Now let me know what is your use case for retrieve specific part of this reversed string.

Can you describe your problem a little better? It’s not clear what you’re trying to achieve with the reverse string and how your example outputs GH.

Or you could try a split and substring function if it is always the 6th value from the beginning. ie:

{
    "type": "substring",
    "attributes": {
        "input": {
            "type": "split",
            "attributes": {
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "attributeName": "name abc",
                        "sourceName": "source xyz"
                    }
                },
                "delimiter": ":",
                "index": 6
            }
        },
        "end": 2,
        "begin": 0
    }
}

You’ll probably need to play around with it for a bit

Thanks
Phil

1 Like

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