Search code examples
formulacrmsugarcrmcalculated-field

Writing the correct formula for SugarCRM


I am trying to automatically populate a field through a calculated field.

Just a quick background we distribute equipment with serials numbers. This equipment is sometimes returned. So some customers have multiple products each with different status of returned, shipped and installed.

I would like to transfer this serial number to a field on the contact through a calculated field only if the status is installed or shipped.

I have tried:

related($products,"serial"),",",(related($products,"status"))

and

related(contains(status,"installed)"products,"serial")

I need this for reporting reasons and would be greatly appreciated if you could help.

Thanks


Solution

  • You need a combination of ifElse and equal and related and or

    As an example, the following Sugar Logic formula can be placed on a Contact record and will populate the field with the related account's name if the related account is of the type "Reseller." If the Account is of some other account_type then the field takes the value of "nope!"

    ifElse(equal(related($accounts,"account_type"),"Reseller"),related($accounts,"name"),"nope!")
    

    If you wanted to add another condition, or allow for another acceptable Account Type, build in an or

    When you're writing lengthy Sugar Logic like this, I find it helpful to start writing it out with indentation using a text editor:

    ifElse(
        or(
            equal(related($accounts,"account_type"),"Reseller"),
            equal(related($accounts,"account_type"),"Investor"),
        ),
        related($accounts,"name"),
        "nope!"
    )
    

    In some versions of Sugar I've had to remove the extra spacing but it seems like in 7.2.2.0 at least the editor actually allows and preservers the formatting, which is a pleasant surprise.