Need help in creating logic/transform by appending letter at the prefix of a numbers

Hye guys,

I have one requirement where we need a transform to append U,UA,UB as prefix to the filenumber attribute which is coming from workday to make USERID attribute.
So requirement is if number is of 6 digit then append U in prefix example : if filenumber from workday is 023456 then output USERID should be U023456

And if the number is a 7 digit number and starting two digit of the nuumber is 10 then in place of 10 we need UA EXAMPLE: if filenumber from workday is coming as 1023456 then output userid shud be UA23456

And same as above if number is 1123456 then we need to repalce 11 with UB and output shud be UB23456 .

kind;ly help me with the rule or transform.

in below identity prifile attribute we need to apply transform

Hi @Apoorv0802,

Here is a sample velocity template that could fit for you :

{
    "id": "350b61cf-acca-4f1c-a3d7-d186b6b7e556",
    "name": "UID_prefix",
    "type": "static",
    "attributes": {
        "ID": {
            "attributes": {
                "attributeName": "File_Number",
                "sourceName": "Employees"
            },
            "type": "accountAttribute"
        },
        "value": "#if($ID.length() == 6)U$ID#{elseif}($ID.length() == 7 && $ID.startsWith(\"10\"))UA$ID.substring(2,$ID.length())#{elseif}($ID.length() == 7 && $ID.startsWith(\"11\"))UB$ID.substring(2,$ID.length())#{else}$ID#end"
    },
    "internal": false
}
4 Likes

THX JESVIN do we need to change source name to workday ? and $ID.length() will be $FILENUMBER.length() right?

got this below error :

There was an exception while calculating the value for this attribute. Error during transformation for attribute: userId (Transform ID: PrefixAppend) Cause: Error rendering template: #if($FILENUMBER.length() == 6)U$FILENUMBER#{elseif}($FILENUMBER.length() == 7 && $FILENUMBER.startsWith(“10”))UA$FILENUMBER.substring(2,$FILENUMBER.length())#{elseif}($FILENUMBER.length() == 7 && $FILENUMBER.startsWith(“11”))UB$FILENUMBER.substring(2,$FILENUMBER.length())#{else}$ID#end

What was the input value? You often get that sort of error message if the input value is missing. You can fix that by adding a firstValid transform and setting a default value if the attribute is NULL

1110230 this is input and UB10230 this is expected output

Have you changed the transform? the error message suggests that you have. Can you show the full transform?

{
“id”: “cc83098f-3723-4110-aa73-f8d0e588994b”,
“name”: “PrefixAppend”,
“type”: “static”,
“attributes”: {
“ID”: {
“attributes”: {
“attributeName”: “FILENUMBER”,
“sourceName”: “Workday”
},
“type”: “accountAttribute”
},
“value”: “#set($FILENUMBER = $FILENUMBER.toString()) #if($FILENUMBER.length() == 6)U$FILENUMBER#{elseif}($FILENUMBER.length() == 7 && $FILENUMBER.startsWith("10"))UA$FILENUMBER.substring(2)#{elseif}($FILENUMBER.length() == 7 && $FILENUMBER.startsWith("11"))UB$FILENUMBER.substring(2)#{else}Unknown#end”
},
“internal”: false
}

change all references of ‘$filenumber’ back to ‘$ID’. You need to reference the “ID” not the content attribute name:

    "attributes": {
        "ID":    <===  reference that 

Jesvin’s transform was spot on

{
“name”: “UID_prefix”,
“type”: “static”,
“attributes”: {
“ID”: {
“attributes”: {
“attributeName”: “FILENUMBER”,
“sourceName”: “Workday”
},
“type”: “accountAttribute”
},
“value”: “#if($ID.length() == 6)U$ID#{elseif}($ID.length() == 7 && $ID.startsWith("10"))UA$ID.substring(2,$ID.length())#{elseif}($ID.length() == 7 && $ID.startsWith("11"))UB$ID.substring(2,$ID.length())#{else}$ID#end”
},
“internal”: false
} is this correct?

1 Like

thanks a lot guys Phil and Jesvin it worked :slight_smile:

Hi @Apoorv0802 - if your issue is resolved, could you please mark the helpful post as the solution?

Hi @Apoorv0802 - Thanks for tagging me as the solution, but maybe you meant @jesvin90 ?

i have corrected it jeremy

1 Like

thanks @jesvin90 :slight_smile: that is great help from you !! appreciated

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