Ok so as you can see in this image, i have a data type with 3 fields, 2 of them already populated. I run a javascript code via “Run javascript” when a button is pressed and this returns a list of numbers. I need to add this list of numbers to the empty field in the POSData data type, adding the 1st item of the list to the empty field of the 1st item in the POSData field, and so on…
The problem is: If i try to use a workflow api i need to store the list returned by javascript into a temporary variable, as i cannot access the “JavascriptToBubble” item in the index through a workflow api. When i store the list, the duplicated values are erased.
Isn´t there a way to join these lists by index number? What can i do? I just need to put the value 1 of the list returned by Javascript into the empty field for value 1 of the POSData and so on.
Have you tried doing a recursive API Workflow so that it updates one POSData at a time?
You can have two parameters for the endpoint:
- List of numbers (this is the JS result)
- Number to process (this is a single number from the list)
When you first trigger it (Schedule an API Workflow - NOT on a list), you pass the full list result in param 1 and then the list’s first item in param 2. Since you’re triggering from a page, you should still be able to do :first item
Then the API workflow will make a change to the first POSData with an empty field 3 (sorted by field 1). Field 3 = Number to process
The last action would Scheduled an API Workflow (itself) to run all over again (this is your recursive loop). The updated parameter values:
Param 1 = List of numbers :minus Number to Process
Param 2 = List of numbers :minus Number to Process :first item
Now, the next time it runs, the list only contains unprocessed numbers and it will process the next in the list.
EDIT
Add a condition to this Schedule action (the one that schedules itself in API Workflows): “Only when List of numbers :minus item Number to Process :count > 0” so that the loop continues as long as there are still items in the list. Once you’ve “minus-ed” all of them away, the count will eventually = 0, failing the condition, and terminating the loop.
Gaby at Coaching No Code Apps (formerly Coaching Bubble)
Courses & Products, Tutorials, Private Coaching, and High-level Development
Start Learning Today
1 Like
Hey romanmg, thank you very much for this approach! I think this is the right way to go and i would have never thought of it. I implemented this and i think i did it the correct way, but i am not getting any result into field 3 of the POSData items.
I am pretty sure this is because the list returned by the javascriptToBubble item is not being read by the API workflow and i do not know why. If i pass this list to a text field, it is displayed correctly. I assume this is the error because:
- The workflow only runs once. As if the condition in the nested workflow didnt pass, meaning the list is empty.
- If i set the api workflow to make a change to the POSData where Field 3 = number to process, field 3 appears to be empty, but if i set Field 3 = 1 then the field will have its value equal to 1.
Here i attach some screenshots of what i did:
Thanks for your help
Hi @simonferro95,
Ok, let’s get this figured out:
-
Is the ListaJS parameter type number? I’m talking about the actual parameter set up, not JavascriptoBubble A’s value.
-
Are there any privacy rules that might be preventing this from running or perhaps you can try with the checkboxes “ignore privacy rules when running the workflow” checked for both “Schedule” actions?
-
Check your server logs. It will say what values were passed through and if the condition on the “nested” Schedule action passed or failed.
Also, I do see one minor correction to make (and I’ve updated my earlier description):
condition should be:
ListaJS :minus item ItemListaJS count > 0
Hello @romanmg
-
Yes, the ListaJS parameter is a number, as seen here:
-
I tried checking the box for “ignore privacy rules” but i get the same result.
-
I checked the server logs and they confirm what i was thinking. The values are not passed into the API workflow, which is very weird
I realised that the BubbleToJS item has a “trigger event” option which creates a “do when bubble to javascript event” in the workflow. I am going to try and add this looping API workflow into the workflow for “do when bubble to javascript event” to see if the values are passed, and i will let you know
Thanks
@romanmg
Hello Gaby,
I tried what i mentioned earlier:
I created the exact same recursive api workflow you mentioned but instead of it being triggered by the press of a button, i triggered it by a “do when bubble to javascript event” which occurs when i push a value from the “run javascript” to a JavascriptToBubble element
The values are now added to field 3 of the POSData items but i get a problem, which is that there are no repeated values passed on, meaning if my list is 1,2,2,3,3,3 i only get 1,2,3
Here i attach the screenshots:
Workflow:
Values created:
Values i need:
As you can see, the values are added to field 3 correctly, but only the unique values, i need all the values to be passed on.
Any help as to what to do is appreciated
Hm, you need to capture that list before Bubble singles them down to unique values. Have you tried using a repeating group (can be hidden) to act as a source for the list? The RG’s type = number, source = javascript value. Then, from the page, pass the RG’s list of numbers to the API workflow.
I’m wondering if it’s that “passing” of number list that strips out any duplicates.
You could also try passing them as a list of texts to see if that helps and convert the text back to a number within the API workflow (there’s a handy, free, data converter plugin for this).