Exploring Dual Transforms for Conditional Operations

I’m looking to utilize the transforms functionality in a dual manner, incorporating two distinct conditions. Specifically, I aim to achieve the following logic:

  1. If a string with a length of 14 characters is provided, the output should be “Y.” Otherwise, it should be “N.”

or

  1. Utilizing the substring function to determine if the first character is “A,” in which case the output should be “Y,” and if not, it should be “N.”

Below is an attempt at implementing this using the substring and lookup functions:

{
    "name": "Deptcode substring TEST",
    "type": "substring",
    "attributes": {
        "begin": 0,
        "end": 1,
        "input": {
            "type": "lookup",
            "attributes": {
                "A": "Y",
                "default": "N"
            }
        }
    },
    "internal": false
}

I’ve drafted this code with the understanding that a lookup function is required for the task. However, I am facing challenges, and it doesn’t seem to be functioning as intended.

Seeking assistance and guidance on how to refine and enhance this implementation for a successful outcome.

Hi Jeongon!

I think simply using a Static transform with some Apache Velocity code could do the job! I like to nest my static transfomrs with a firstValid to null check:

{
    "name": "XYZ",
    "type": "static",
    "attributes": {
        "attributeXYZ": {
            "attributes": {
                "values": [
                    {
                        "attributes": {
                            "attributeName": "XYZ",
                            "sourceName": "XYZ"
                        },
                        "type": "accountAttribute"
                    },
                    "null"
                ]
            },
            "type": "firstValid"
        },
        "value": "#if($attributeXYZ != 'null' && $attributeXYZ.length() == 14)Y#{else}N#end"
    },
    "internal": false
}

I have not verified the transform but something like this should work :slight_smile:

1 Like

Hi @joyoon00 ,

{
    "name": "Test",
    "type": "static",
    "attributes": {
        "Substring_Transform": {
            "attributes": {
                "begin": 0,
                "end": 1
            },
            "type": "substring"
        },
        "value": "#if($Substring_Transform=='A')Y#{else}N#end"
    },
    "internal": false
}

Try this, it work’s for me.

Thanks!

2 Likes

Hi Jeongon Yoon,

You can also try the transform below.
It’s similar to the other transform that are shared, I’ve just added trim transform in case of any bad data. I’ve tested the transform and it works fine for me.

{
    "name": "XYZ",
    "type": "static",
    "attributes": {
        "ATXYZ": {
            "attributes": {
                "begin": 0,
                "end": 1,
                "input": {
                    "attributes": {
                        "input": {
                            "attributes": {
                                "sourceName": "sp-xyz",
                                "attributeName": "sp-attribute"
                            },
                            "type": "accountAttribute"
                        }
                    },
                    "type": "trim"
                }
            },
            "type": "substring"
        },
        "value": "#if($ATXYZ == 'A')Y#{else}N#end"
    },
    "internal": false
}
2 Likes

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