Data Sources - dynamic calculations and data export

Hello - I have some questions relating to using Data Sources:

  • What is the correct approach to make and use calculations based on values in a Data Source field? For example, if a user enters a date on a form that is stored in a Data Source row, I need a dynamic field that calculates the number of days between today and that date (with some error handling etc). In a spreadsheet this would be easy but I can’t see how this could be replicated here. Is the only approach to calculate these things on the fly, using Javascript?
  • Similarly, what’s the best approach to adding a look-up based on the Data Source value? For example, a user chooses an item from a dropdown list, and the Data Source table stores this together with a category field based on looking up the item in a separate developer-maintained list?
  • Is it possible to access a particular Data Source via an API or to export a CSV in an automated way, for example once a day, ideally via secure file transfer? This would be to faciliate back-end scripting, for example, creating emails based on a Data Source contents to be sent via a separate email service.
    Thank you!

Hi brass,

  1. The correct approach to make calculations would be to use JavaScript on the fly in the form to calculate. You can use Moment.js to do such calculations easily. Depends on where the data is shown you would have to request the data from the data source and loop through the records to calculate the difference for each record. If you are getting the data manually you can use this JS API. Data Sources JS APIs | Fliplet Developers Documentation

  2. You can use our form JS API and the DS JS API mentioned above to do this. We have a change event for drop downs which you can detect and either executes looks up against a data source.
    See: Form JS APIs | Fliplet Developers Documentation and Form JS APIs | Fliplet Developers Documentation. To see an example of this, in Fliplet Studio when you click on “Add screen” you can see the “Form with drop-down from data source” screen. Add that to your app to get an idea of the code required.

  3. You can access your data source using our REST API to do the actions you are looking for. See: Data Sources REST APIs | Fliplet Developers Documentation

Hope this helps!
Deb

Great - thank you for your reply Deb

@Deb , appreciated your answer to @brass . Could I ask a related question please? I’m a brand new user (literally 24 hours). I need to make calculations for a metrics dashboard. (I’m a little shocked that there’s nothing in the stack of components - maybe in the data visualization category. I need to calculate a) the total of all the numbers reported in a particular field (column) from every user’s report post for the year to day, b) the figure that the user posted as the latest figure for another metric. (In other words, the most up-to-date value in a given numeric field, as reported by every user who created a database entry in the stack of entries for a particular table.) Where do I input the formulae for these metrics??? Thank you for any help you can give.
Doug

Hi Doug,

You will have to use our data source JS API to connect to the datasource and get all the relevant data and then you will have to use javascript to do the calculations and also use Javascript to show it on a screen if that is necessary.

You can see our data source JS API here. Data Sources JS APIs | Fliplet Developers Documentation

I’m sure chatGPT will be able to help you with the code to do the calculations if necessary.

Thanks,
Deb