Difficulty creating transform with concat + table and velocity

Basically I need a transform that will be a concat of the company acronym + employee registration number.

It doesn’t happen that the acronym will change according to the registration number. I’m trying the way below but it gives an error in the print screen.

{
    "name": "BI_COLIGADA_PREFIXO_V11.7",
    "type": "concat",
    "attributes": {
        "values": [
            {
                "attributes": {
                    "siglaEmpresa":{
                        "type": "lookup",
                        "input": {
                        "attributes": {
                            "attributeName": "NOME_EMPRESA",
                            "sourceName": "TOTVS - Autoritativo"
                        },
                        "type": "accountAttribute"
                        },
                        "table": {
                            "Company 1": "BI",
                            "Company 2": "DM",
                            "Company 3": "DT",
                            "Company 4": "FR",
                        }
                    },
                    "chapa":{
                        "type": "accountAttribute",
                        "attributes": {
                            "attributeName": "CHAPA",
                            "sourceName": "TOTVS - Autoritativo"
                        }
                    },
                    "value": "#if($chapa>9999)'BT'#{else}$siglaEmpresa"
                }
            },
            {
                "attributes": {
                    "padding": "0",
                    "length": "6",
                    "input": {
                        "type": "accountAttribute",
                        "attributes": {
                            "attributeName": "CHAPA",
                            "sourceName": "TOTVS - Autoritativo"
                        }
                    }
                },
                "type": "leftPad"
            }
        ]
    },
    "internal": false
}

Hi Bruno,
You don’t need the “attributes”:{} that is inside the first part of the concat.
Beyond that, I recommend that you build the transform slowly and in stages.

Try this as your first stage:

{
  "name": "BI_COLIGADA_PREFIXO_V11.7",
  "type": "firstValid",
  "attributes": {
    "values": [
      {
        "siglaEmpresa": {
          "type": "lookup",
          "input": {
            "type": "accountAttribute",
            "attributes": {
              "attributeName": "NOME_EMPRESA",
              "sourceName": "TOTVS - Autoritativo"
            }
          },
          "table": {
            "Company 1": "BI",
            "Company 2": "DM",
            "Company 3": "DT",
            "Company 4": "FR",
            "default": "XXX1"
          }
        }
      },
      "XXX2"
    ]
  }
}

Hi @raibom , transform type should be static as per the velocity condition given. Also, you can use “leftpad” transform in the same “chapa” attribute transform instead of doing it separately.

1 Like

Hi @raibom ,

Try the below transform.

{
    "name": "BI_COLIGADA_PREFIXO_V11.7",
    "type": "concat",
    "attributes": {
        "values": [
            {
                "type": "static",
                "attributes": {
                    "siglaEmpresa": {
                        "type": "lookup",
                        "attributes": {
                            "input": {
                                "type": "accountAttribute",
                                "attributes": {
                                    "sourceName": "TOTVS - Autoritativo",
                                    "attributeName": "NOME_EMPRESA"
                                }
                            },
                            "table": {
                                "Company 1": "BI",
                                "Company 2": "DM",
                                "Company 3": "DT",
                                "Company 4": "FR",
                                "default": "ABC"
                            }
                        }
                    },
                    "chapa": {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "TOTVS - Autoritativo",
                            "attributeName": "CHAPA"
                        }
                    },
                    "value": "#if($chapa>9999)'BT'#{else}$siglaEmpresa#end"
                }
            },
            {
                "type": "leftPad",
                "attributes": {
                    "padding": "0",
                    "length": "6",
                    "input": {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "TOTVS - Autoritativo",
                            "attributeName": "CHAPA"
                        }
                    }
                }
            }
        ]
    }
}

Thanks!

1 Like

I had 2 problems, the first was that I had to use the type: “static” and I didn’t know that.
Second, I was missing the #end in the velocity template.
After correcting it, it looked like this:

{
    "name": "BI_COLIGADA_PREFIXO_V11.14",
    "type": "concat",
    "attributes": {
        "values": [
            {
                "type": "static",
                "attributes": {
                    "companyAcronym": {
                        "type": "lookup",
                        "attributes": {
                            "input": {
                                "attributes": {
                                    "attributeName": "NOME_EMPRESA",
                                    "sourceName": "TOTVS - Autoritativo"
                                },
                                "type": "accountAttribute"
                            },
                            "table": {
                                "Company 1": "BI",
                                "Company 2": "DM",
                                "Company 3": "DT",
                                "Company 4": "FR",
                                "default": "XXX1"
                            }
                        }
                    },
                    "employeeNumber": {
                        "type": "accountAttribute",
                        "attributes": {
                            "attributeName": "CHAPA",
                            "sourceName": "TOTVS - Autoritativo"
                        }
                    },
                    "value": "#if($employeeNumber>9999)'BT'#{else}$companyAcronym#end"
                }
            },
            {
                "type": "leftPad",
                "attributes": {
                    "padding": "0",
                    "length": "6",
                    "input": {
                        "type": "accountAttribute",
                        "attributes": {
                            "attributeName": "CHAPA",
                            "sourceName": "TOTVS - Autoritativo"
                        }
                    }
                }
            }
        ]
    },
    "internal": false
}

Now I’m trying to remove the leftPad operation, doing it directly in velocity but I’m having problems. I tried this way using copilot but it gave an error as shown in the print screen:

Template: #if($employeeNumber>9999)'BT' + $employeeNumber.pad(6, '0')#{else}$companyAcronym + $employeeNumber.pad(6, '0')#end

Hi @raibom, can you get us one example with the use case what exactly you are trying to do? It will be helpful for us to help you with the transform.

Hi @raibom ,

I have a question, like why are you moving it inside static method?

Is the above given transform, didn’t satisfy any requirements?

@JackSparrow , What I want now is to do the left padding directly in velocity. As I showed in the last example, sailpoint doesn’t seem to recognize this .pad method.
I would like to know if this is possible.

@GOKUL_ANANTH_M, The trasnform with “type”: “leftPad” did work. I would just like to know if it would be possible to do the left padding directly in velocity. This way the transformation would be smaller and more objective.

Hi @raibom ,

"value": "#set($desiredLength = 10)#set($paddingChar = '0')#if($employeeNumber > 9999)#set($paddedString = '${paddingChar.substring(0, $desiredLength - 2)}BT')#else#set($paddedString = '${paddingChar.substring(0, $desiredLength - $companyAcronym.length())}$companyAcronym')#end"

I think with the help of this, you can get the desired output. I didn’t test this, please inform us if it helps. Thanks!!

I preferred to use “type”: “leftPad”, as this code ended up being very large and difficult to understand for future maintenance.

@GOKUL_ANANTH_M Is there any way to convert the character to an integer?
I say this because my transform didn’t work. The variable $employeeNumber comes with the value 010000 and I need to convert it before the condition. I tried $employeeNumber.parseInt() but it gives a template error.

It worked with

"value": "#set($chapaInt = 0)#if($chapaInt.parseInt($chapa)>9999)BI#{else}$siglaEmpresa#end"
2 Likes