Transform to introduce space

Hello everyone,

I’ve created a transform to build a mobile number. The transform is working fine.
mobile: +491753014148, +49175, +49 etc,

but we need to introduce the space in between conditionally as per the value existence as below?
+49 175 3014148, +49 175, +49

{
  "name": "MobileNumber",
  "type": "e164phone",
  "attributes": {
    "input": {
      "attributes": {
        "MOBI_AREA": {
          "attributes": {
            "ignoreErrors": true,
            "values": [
              {
                "type": "accountAttribute",
                "attributes": {
                  "sourceName": "*****",
                  "attributeName": "MOBI_AREA"
                }
              },
              "None"
            ]
          },
          "type": "firstValid"
        },
        "MOBI_VORW": {
          "attributes": {
            "ignoreErrors": true,
            "values": [
              {
                "type": "accountAttribute",
                "attributes": {
                  "sourceName": "*****",
                  "attributeName": "MOBI_VORW"
                }
              },
              "None"
            ]
          },
          "type": "firstValid"
        },
        "MOBI_TELN": {
          "attributes": {
            "ignoreErrors": true,
            "values": [
              {
                "type": "accountAttribute",
                "attributes": {
                  "sourceName": "*****",
                  "attributeName": "MOBI_TELN"
                }
              },
              "None"
            ]
          },
          "type": "firstValid"
        },
        "MOBI_EXTN": {
          "attributes": {
            "ignoreErrors": true,
            "values": [
              {
                "type": "accountAttribute",
                "attributes": {
                  "sourceName": "*****",
                  "attributeName": "MOBI_EXTN"
                }
              },
              "None"
            ]
          },
          "type": "firstValid"
        },
        "default": {
          "type": "static",
          "attributes": {
            "value": ""
          }
        },
        "value": "#if($MOBI_VORW !='None' && $MOBI_TELN !='None' && $MOBI_EXTN !='None')$MOBI_VORW$MOBI_TELN$MOBI_EXTN#{elseif} ($MOBI_VORW !='None' && $MOBI_TELN !='None')$MOBI_VORW$MOBI_TELN#{elseif} ($MOBI_VORW !='None')$MOBI_VORW#{else}$default#end"
      },
      "type": "static"
    },
    "defaultRegion": {
      "type": "lookup",
      "attributes": {
        "table": {
          "1": "US",
          "7": "RU",
          "20": "EG",
          "27": "ZA",
          "30": "GR",
          "31": "NL",
          "32": "BE",
          "33": "FR",
          "34": "ES",
          "36": "HU",
          "39": "IT",
          "211": "SS",
          "212": "EH",
          "213": "DZ",
          "216": "TN",
          "1-684": "AS",
          "1-264": "AI",
          "1-268": "AG",
          "1-242": "BS",
          "1-246": "BB",
          "1-441": "BM",
          "44-1481": "GG",
          "44-1624": "IM",
          "1-876": "JM",
          "44-1534": "JE",
          "1-664": "MS",
          "1-670": "MP",
          "1-787": "PR",
          "default": "US"
        },
        "input": {
          "type": "accountAttribute",
          "attributes": {
            "sourceName": "*****",
            "attributeName": "MOBI_AREA"
          }
        }
      }
    }
  },
  "internal": false
}

Hi @Shonnegowda,

In static value definition you can directly introduce space beetween $MOBI_VORW and $MOBI_TELN :
For example you have : $MOBI_VORW$MOBI_TELN that must be $MOBI_VORW $MOBI_TELN

...
“value”: “#if($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’ && $MOBI_EXTN !=‘None’)$MOBI_VORW $MOBI_TELN $MOBI_EXTN#{elseif} ($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’)$MOBI_VORW $MOBI_TELN#{elseif} ($MOBI_VORW !=‘None’)$MOBI_VORW#{else}$default#end”...

But if you to introduce space on $MOBI_TELN for example you must substring value base your need and then use foreach loop for concatenate this substring.

Example of substring and static concatenation with space :

"value":  "#set($firstPartOfMOBI_TELN=$MOBI_TELN.substring(0,2))#set($secondPartOfMOBI_TELN =$MOBI_TELN.substring(2,$MOBI_TELN.length()))#set($newMOBI_TELN='$firstPartOfMOBI_TELN $secondPartOfMOBI_TELN')"
1 Like

You may use space in this format as given below :

"value": "#set ($emptySpace = " ") #if($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’ && $MOBI_EXTN !=‘None’)$MOBI_VORW$emptySpace$MOBI_TELN$MOBI_EXTN#{elseif} ($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’)$MOBI_VORW$MOBI_TELN#{elseif} ($MOBI_VORW !=‘None’)$MOBI_VORW#{else}$default#end"
1 Like

Thanks for the quick response!

I’ve tested this earlier, but we do have E.164 phone type transform as the main type, so not introducing the space, even though we added it as you mentioned. if I remove the E.164 transform then I can introduce the space, but default region value will be missed.

With E.164 phone transform +13142438088
Without E.164 phone transform 314 2438088
Expected value +1 314 2438088

@Shonnegowda introducing space work ?

I’ve to remove “type”: “e164phone” to work that, but it will constraint me from getting the default region as per the code, since I’ve to remove “default region” attribute, which comes with “type”: “e164phone” transform. This in turn not meeting my requirement of getting the regional code

Can we not simply avoid e164phone and do the lookup in static way only, like the sample below. May be some attributes can be adjusted as per need.

{
    "attributes": {
        "MOBI_AREA": {
            "attributes": {
                "ignoreErrors": true,
                "values": [
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "*****",
                            "attributeName": "MOBI_AREA"
                        }
                    },
                    "None"
                ]
            },
            "type": "firstValid"
        },
        "MOBI_VORW": {
            "attributes": {
                "ignoreErrors": true,
                "values": [
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "*****",
                            "attributeName": "MOBI_VORW"
                        }
                    },
                    "None"
                ]
            },
            "type": "firstValid"
        },
        "MOBI_TELN": {
            "attributes": {
                "ignoreErrors": true,
                "values": [
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "*****",
                            "attributeName": "MOBI_TELN"
                        }
                    },
                    "None"
                ]
            },
            "type": "firstValid"
        },
        "MOBI_EXTN": {
            "attributes": {
                "ignoreErrors": true,
                "values": [
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "*****",
                            "attributeName": "MOBI_EXTN"
                        }
                    },
                    "None"
                ]
            },
            "type": "firstValid"
        },
        "ownDefaultRegion": {
            "type": "lookup",
            "attributes": {
                "table": {
                    "1": "US",
                    "7": "RU",
                    "20": "EG",
                    "27": "ZA",
                    "30": "GR",
                    "31": "NL",
                    "32": "BE",
                    "33": "FR",
                    "34": "ES",
                    "36": "HU",
                    "39": "IT",
                    "211": "SS",
                    "212": "EH",
                    "213": "DZ",
                    "216": "TN",
                    "1-684": "AS",
                    "1-264": "AI",
                    "1-268": "AG",
                    "1-242": "BS",
                    "1-246": "BB",
                    "1-441": "BM",
                    "44-1481": "GG",
                    "44-1624": "IM",
                    "1-876": "JM",
                    "44-1534": "JE",
                    "1-664": "MS",
                    "1-670": "MP",
                    "1-787": "PR",
                    "default": "US"
                },
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "sourceName": "*****",
                        "attributeName": "MOBI_AREA"
                    }
                }
            }
        },
        "default": {
            "type": "static",
            "attributes": {
                "value": ""
            }
        },
        "value": "#set ($emptySpace = ' ')#if($MOBI_VORW !='None' && $MOBI_TELN !='None' && $MOBI_EXTN !='None')$ownDefaultRegion$emptySpace$MOBI_VORW$MOBI_TELN$emptySpace$MOBI_EXTN#{elseif} ($MOBI_VORW !='None' && $MOBI_TELN !='None')$ownDefaultRegion$emptySpace$MOBI_VORW$emptySpace$MOBI_TELN#{elseif} ($MOBI_VORW !='None')$MOBI_VORW#{else}$default#end"
    },
    "type": "static",
    "internal": false
}
1 Like

Thanks for the input!! Appreciated

The static variable to calculate the default region should work. To set the space, we can just use direct space in between the variables as below.
.
“value”: “#if($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’ && $MOBI_EXTN !=‘None’)+$defaultRegionCode $MOBI_VORW $MOBI_TELN $MOBI_EXTN#{elseif} ($MOBI_VORW !=‘None’ && $MOBI_TELN !=‘None’)+$defaultRegionCode $MOBI_VORW $MOBI_TELN#{elseif} ($MOBI_VORW !=‘None’)+$defaultRegionCode $MOBI_VORW#{else}$default#end”

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