calculated field - if value starts with .. select this: SOLVED

Hi,

i have a question about calculated fields.

Use Case is: We'd like to cluster living-areas. 

Therefore i need something like a calculated field thats selects for example Reagion1 if the zipcode in the linked field/module starts with 3.

Thanks!

  • Hi Lennart Gebauer 

    You can use the SugarLogic function subStr(string, star, leng).

    So, as per your scenario, we have:

    ifElse(

       equal(subStr($some_field, 0, 1), "3"),

       // do something

       // do something else

    )

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hey, 

    thanks for the reply.

    So i tried it and i use the following formular

    ifElse(
    isWithinRange(rollupSum($zipcode_short_c,"amount"),01,09),
    "Sachsen",
    ifElse(
    isWithinRange(rollupSum($zipcode_short_c,"amount"),10,19),
    "Brandenburg",
    ifElse(
    isWithinRange(rollupSum($zipcode_short_c,"amount"),20,29),
    "Hamburg",
    ifElse(
    greaterThan(rollupSum($zipcode_short_c,"amount"),30),
    "keine Region",
    "0"
    )
    )
    )
    )

    But there is a error:

    Ungültige Formel 
    "Unexpected token I in JSON at position 0"

    Any suggestions?


    Thanks!

  • I got this working formula in my dev instance:

    ifElse(
    isWithinRange(rollupSum($opportunities, "amount"), 1 ,9),
    "Sachsen",
    ifElse(
    isWithinRange(rollupSum($opportunities, "amount"), 10, 19),
    "Brandenburg",
    ifElse(
    isWithinRange(rollupSum($opportunities, "amount"), 20, 29),
    "Hamburg",
    ifElse(
    greaterThan(rollupSum($opportunities, "amount"), 30),
    "keine Region",
    "0"
    )
    )
    )
    )

    You just need to replace the link name at the rollupSum formula.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Used your fourmula  and replaced the fieldname.

    still the same error

    Unexpected token I in JSON at position 0

  • So I believe there is an issue in your custom link/relationship.

    I had tested in the default opportunities link under Accounts.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • yeah,

    so actually it's all in one module

    so the field that is calculated (region_c) get's it's value from a field (zipcode_short_c) in the same module

    is that maybe the reason?

  • Definitely yes!

    So the formula may looks like that one:

    ifElse(
    isWithinRange($zipcode_short_c, 1 ,9),
    "Sachsen",
    ifElse(
    isWithinRange($zipcode_short_c, 10, 19),
    "Brandenburg",
    ifElse(
    isWithinRange($zipcode_short_c, 20, 29),
    "Hamburg",
    ifElse(
    greaterThan($zipcode_short_c, 30),
    "keine Region",
    "0"
    )
    )
    )
    )

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • ok, and the zipcode_short_c must be a number probably?

    because right now it is a textfield.

  • Certain it should be a number (either integer or float).

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • now it says: the formula must be boolean ..

    i'm going crazy

    the whole workaround.

    all the fields are in the same module.

    i use a related formula to get the first 2 digits of the zipcode.

    then i'd like to use the formular to set a region as value defined by the first 2 digits.

    zipcode it textfield - out of the box

    short zipcode - i tried all number fields

1 2