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.