Need Help With Nested Loops

I am creating a page that will allow scheduling of social media posts to multiple social media accounts, across multiple platforms, and at scheduled times. The goal is to allow a user to select multiple Social Media accounts (i.e. multiple facebook, twitter, etc), select multiple social media platforms (facebook, twitter, instagram, youtube), select multiple dates/times for the posting all from one screen.

I need to create a new thing for each of the selections (Account-Platform-Date). The text and the file url (image, video) for the post is already housed in the database as separate things that will be passed with the call of the API. This is basically a loop nested inside a loop nested inside another loop. I saw that you can call an API on a list but not sure how to do any of the other nesting. Any help, would be great. Thanks!

Inside the RG you can have a text item for example that is another RG or does a search.


(in this example i’m looking into another list to extract item with same index as the cell i’m on in my main RG)

There are some plugins that might be able to help as well like maybe list shifter or some of the general utilities, but i’m not familiar with them.

Hope that helps a little.

you could try this also

depends on your data.

This could help, I’m not sure: [New Plugin] Bdk Utilities

I think you are misunderstanding what I am trying to do. I need for the workflow to cycle through 3 nested loops, based on the values of the inputs in my screenshot.

Ok this is easy with API workflows
Create one workflow to add a single instance. It should accept an account, a platform and a date.
Create a second workflow that accepts an account, a platform and a list of dates.
In this workflow, schedule an api workflow on a list, and loop the dates

Create a third workflow that accepts an account, a list of platforms, and a list of dates
Loop into workflow 2 from there

In your page you can create an api workflow on a list. Run that on your account data

I personally prefer to have a fourth workflow that you pass all three lists to, because then the initiation of the workflows is fast on screen and the user perceives better performance.

What to watch for…, check your capacity that when you run a chunky number of permutations, that you don’t max out your app. If you do, split out the workflows spacing interval wider.

I kind of understand what you are saying but have a lot of questions. I have tried to outline them all in the attached picture.

Any help would be greatly appreciated.

Ok you are getting there.

On your page you need your three controls each to have a custom state which is a list of the things it displays. As you select items, the state should update.

So on your page you now have three states in three controls full of the lists you have selected.

In your picture you describe what triggers the workflow. On your page, when you trigger that, make your page run an api workflow on a list, of workflow single-list-list

List to run on is the list of accounts from your state or element.
Pass in THIS ACCOUNT
and the two lists

Inside the single-list-list workflow, add an action to run an api workflow on a list, run the single-single-list workflow
List to run on is the list of platforms

Pass in the parameter account already received
Pass in THIS PLATFORM
and the final list of dates

Inside the sing-single-list workflow trigger an api workflow on a list for the final all singles workflow

List to run on is your list of dates
Pass through your account and platform parameters
Pass THIS DATE

Your all singles workflow receives three parameters and you can create your item from there

Your page needs to compile the three separate lists, and the workflows explode them into singles

Ok, I have the loops writing data and creating the individual things. However, it is creating the incorrect things. On the page, I have the profile, platform, and date populating list fields in a thing in Data Type, Social Post. I know you said that I should create a state for each one but since I was already storing them in a thing I thought this would work. Here is a screen shot of that thing:

I have configured the API, on button change, as follows. As the Social Post will contain a lot of postings, I am trying to find the one that I currently working on, by matching the unique id, and return the fields needed.

I have configured the platform and date similarly, by again trying to get the appropriate list by matching the current Social Post unique id.

However, the problem, I am having is that it is posting all of the platforms and all of the dates, even when they are not associated with this Social Post unique id. See below.

In the image above, I first created a Social Post tested a posting on Mar 16. I then created a second Social Post and did a test post for Mar 6. (You can see both Social Posts in the first image at the top. As you can see, each submission created a record for each platform event though only one was in the thing (see first image) and it created a new thing for every date, even though each thing only had one date (the dates are stored in a separate table).

I know I am close, I just don’t understand why it is not filtering the date correctly. What did I miss? Thanks!

Ok one of the things you did differently to my notes were your parameter data types. You’re passing in lists of texts from your data

If you set up your parameters to be account, platform and profile as a list or single depending on the workflow, you can look up the textual values you need later

Once you’re in api workflows you cannot see the page any more but you can go “account’s fieldvalue” to put them in your create.

On your page your first workflow should be running on a list of accounts. A list of profiles, a list of dates (this date).

Don’t send the dates through formatted. Format them at the end in the single single single workflow.

Next, your list of platforms and your list of dates appear to be coming form searches. When you first posted you gave us this…

THAT is a list of accounts and a list of platforms and a list of dates. Make your lists from those. Not from searching on other things.

Make those into your lists and put them through the workflow

Your two intermediate level workflows should not search for any data whatsoever. They only exist to expand the permutations.

Finally, I do not recommend you schedule your calls 0.001s apart. First, bubble won’t let you do that anyway, but if you did schedule ten posts on four accounts on five platforms, that’s 200 items more or less simultaneously and bubble will just die. It will write some of them but not all, throw some errors and not create others with no errors.

Schedule your first call maybe 6s apart, your second maybe 3, and your final one 1s apart. It will be more reliable. If you give bubble way too much to do in the same second, it gets flaky.

Richard

I am not sure what is going on. I have changed it to look at the values of the input fields (see below) but I still getting things created for all of the platform options and all dates that exist in the database. I don’t understand why it is not taking the values of the inputs.

What am I missing? Thanks for your help.

From what I see you’re on the page.
The page is calling the api workflow for single account, and lists of profiles and dates

So your list to run on needs to be accounts
And it needs to send “this account” into the workflow.
And the two lists into the other two parameters.

Do that first.

Ok, I have made the changes you suggested and so here is the latest to start off my workflow. platform and post_date are elements that contain lists of the inputs. I have verified that they are working via the inspect tool.

When I get into the single-list-list end point, I should set the “List to run” to what? I am not presented with many options (the 4 variables that I am passing or a lookup). If I select platform, I get red letters like it won’t me complete it. This is where I was doing a lookup but you said not to do that.

Hi
So your page calls single-list-list
Your single-list-list calls single-single-list
And that calls single-single-single
It should be right…,
Let me look at screenshots again…

Check this evaluates to a list…

Yes, platform evaluates to a list of texts and date evaluates to a list of dates in the starting API when my dropdown changes values.

However, in the Single Account - List Platform - List Date endpoint, when I schedule an API Workflow on List and select Single Account - Single Platform - List Date, it’s not letting me select the list to run on. I should be able to select the key, platform, that was passed, correct? It’s giving me the same error when I select the date in the next endpoint.

Ok, I made some progress. In the endpoint keys, I had the data type for platform set as text. I changed it to Social Platforms as it is a data set within my database. The same with date.

Screen Shot 2021-03-18 at 9.14.23 AM

I made all of the subsequent changes in the other endpoints. Now, when the API runs, I am getting the appropriate number of things created.

However, as you can see, the date is populating, but the social_account and the social_platform is not populating. Here is how I have that configured. If I try to choose account name (instead of just account), I get the red error. So, I am not sure why I am getting empty values. It has to be passing something as I am getting the correct number of things created.

Screen Shot 2021-03-18 at 9.14.35 AM

Can you show me the attributes list for your post table?

Here is a screenshot of the table attributes where the things will be created.

Screen Shot 2021-03-18 at 2.46.45 PM

Can I see the inputs for your final api workflow?

Here is the final workflow where the thing is created.

Screen Shot 2021-03-18 at 3.00.17 PM