Converting text to date - JS2B Element not saving conversion fast enough

Hi!

What is the best way to convert text-dates received from an API, to dates? My database has fields of date types and the API returns text-dates which need to be converted to dates before committing to my database. I do not want to use text for dates in my database.

I am currently converting the text dates by using the Toolbox plugin’s JS2B element + Run JS action.

Making use of this method converts the dates successfully, however, this method requires the JS2B element to be on the page for retrieving it’s output (i.o.w. its not a workflow action). An expression can also be used for converting the text to dates.

The Problem:
When triggering a workflow that relies on the output of the JS2B element, it appears that because bubble’s workflows run synchronously and fast, the referenced JS2B element appears empty (does’nt receive converted dates fast enough) when the workflow runs to the point where it references the JS2B element’s output. I have tried adding a pause’s and custom events in my workflow, however this doesn’t solve the issue. Only when the workflow is run for a second time does the output element have saved values from the previous run workflow.

Example Workflow
Sync Data Btn clicked >> API returns text-based-dates: (DeliverByDate, InspectByDate, DeletedAtDate) >> Set 3 text Custom States to previous steps return values: Element: Popup-SyncTx’s: Custom States: apiTxtAmendDeliverBy (text)​, apiTxtAmendInspectBy (text)​, apiTxtAmendDeletedAt (text) >> Run JS (Converts 3 x Custom States, text to dates) >> Make Changes to a thing: Inside this event, added actions to update the database fields (DeliverBy, InspectBy, DeletedAt) with the corresponding outputs from the JS2B element.

Every time this workflow runs for the first time, the JS2B element is empty when the “Make changes to a thing” workflow action sends data to database.

You can do something like i did in this example:

Link to editor: Rrdev-tips | Bubble Editor

Demo: https://rrdev-tips.bubbleapps.io/version-test/date_converter?debug_mode=true

Hi @f.bornman ,

Do you have an example of the date you are receiving?

Depending on it, you could just set the field as date from the API connector without using a plugin. Basically, if the text is in a standard date format, Bubble will convert it for you.

Hey @esardila,
Thanks for that. I reinitialised the specific API call in the API connector, and in the confirmation I set the date values from text to Date. This solved the issue!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.