App variable to be used in an equation

It would be nice if I could use a global variable in an equation in the data builder.

Use case:
We calculate for our sales price with a fixed exchange rate.
My solution would have been: make a table with one record only: the exchange rate.
Make a app variable from this record (this works already).
Alas in an equation I can not use this app variable.

Chem told me there is a workaround, but it would be great if you have global variables.

This is not the same, but also in the same direction: Page Variable suggestion

I’m interested in this too.

Chem did send me a suggestion around using JavaScript and the user logged in variables, but it was a bit too geeky for me. It made total sense the way he explained it, but it had a lot of moving parts and I was concerned about my ability to support / extend that solution.

Has something like this ever come to fruition? This functionality would be very useful!

This is likely not going to even be possible since all our equations are server side at the database level.

However, is this a value that’s only being used in view only? In that case, you might be able to achieve this with a dynamic field.

I’ll test this idea and report back.

Yes, you can achieve this using a combination of local storage and a custom Handlebars helper. Here’s how:

Steps

  1. Store the exchange rate in local storage:
localStorage.setItem('exchange_rate', '0.8790'); // Example rate
  1. Create a custom Handlebars helper:
Handlebars.registerHelper('multiplyByExchangeRate', function (value) {
  const rate = parseFloat(localStorage.getItem('exchange_rate')) || 0;
  return value * rate;
});
  1. Use the helper in your dynamic field:
{{multiplyByExchangeRate field_73}}

Be sure to wrap the Handlebars helper in event listener:

document.addEventListener('DOMContentLoaded', function () {
    
    Handlebars.registerHelper('multiplyByExchangeRate', function (value) {
            const rate = parseFloat(localStorage.getItem('exchange_rate')) || 0;
            return value * rate;
        });
    
  });

Here’s some screenshots of my configuration:

Important Notes

  • This approach works only on the client-side (within the app interface).
  • It won’t apply to server-side processes like exports or backend calculations.
  • ChatGPT is amazing at writing the most powerful Handlebar Helpers.

Let me know if you need further clarification or assistance!

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