How to know the currency of a field?

Hi everyone,

I need to access the currency type (ISO 4217) of a currency field because I need to print it in a pdf. I'm using the pdf manager to get the values of the fields from the actual record. Is there a way to get the currency type from the pdf manager?

Parents
  • There is no easy way...

    There is only one currency per record, its id is in currency_id

    The PDF amounts are formatted using the currency symbol rather than the currency's ISO4217

    It would be really nice if there was a choice on which to use in the PDFs.

    The only way I can think of to do what you need is to add a custom field to your module to hold that value, then include it in your PDF using smarty to format the amount without a symbol.

    So your before_save logic hook will have something like:

     

    if ($bean->currency_id == '-99'){
        $bean->reporting_currency_c = 'USD';
    }else{
        $currencyBean = BeanFactory::retrieveBean('Currencies', $bean->currency_id);
        $bean->reporting_currency_c = $currencyBean->iso4217;
    }

    Note that your default currency has ID -99, for us that's USD

    Hope this helps,
    FrancescaS

Reply Children
  • I believe there is a better solution.

    You can create a varchar field "iso4217" in the target module and setup the following sugarLogic formula:

    ifElse(equal($currency_id, "-99"), "USD", related($currencies, "iso4217"))

    Unfortunately you can not configure such formula through Studio because SugarLogic engine doesn't "see" the field "currency_id", so you will need to place it directaly in the field's extended vardefs.

    Finaly you run QRR and it is done.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada