'Unexpected Not Ready' while testing Plugin

I’m looking for some advice with developing Plugins.
This could just be a javascript thing as well (I’m an amateur at JS tbh).

I’ve been trying to build a new plugin that needs to make use of a lot of data.
I’m currently struggling with getting my Plugin to convert a list of things of custom ‘User’ type to a JSON object that I can access in my Plugin code.

Firstly, is this a good approach to working with data? - Grabbing all the data at the start and storing it in a local variable.

Secondly, when I try to do this, it errors out on the Browser.
Here’s the error it throws:

I’m running this as an action

*myUsersList contains a list of Users supplied by the user in the Action properties.
Here’s my code:

let prop2jsonUsers = context.async(async callback => {
  	var prop = properties.myUsersList;
      if(prop === null){
        return null;
    try {
        var res = [];
        if (prop.length() > 0) {
            var thingsList = prop;
            var thingProperties = await thingsList.get(0,1)[0].listProperties();

            for (var itms=0, lni=prop.length(); itms < lni; itms++) {
                var myObj = {};
                for (var j=0, lnj=thingProperties.length; j < lnj; j++) {
                    myObj[thingProperties[j]] = await thingsList.get(itms,1)[0].get(thingProperties[j]);
                res[itms] = myObj;
        callback(null, res);
  	catch (err) {

My goal is to retrieve 7 such lists of things and convert them to JSON objects in local variables. From trials so far, I’ve understood that since the .get() function is asynchronous, the resulting JSON object doesn’t find any data to populate with.
I’m wondering what a best practice for such a dev case would be.

Thanks for going through this!

Have you read this: Loading Data - Bubble Docs ?

It may explain the behaviour you’re seeing but I’m not sure if it helps solve it. One workaround to get the list you want is to choose “Any thing” as the property type of your plugin element instead of User and then in the app editor set the property’s value to a list of users. That seems to work for me with your code but it does mean that you won’t be able to constrain the field to only accept a list of users.

One small change I might suggest to your code , based on the recommendations in the link above, is to load your data first. So …
instance.data.myUsersList = properties.myUsersList;
let prop2jsonUsers = context.async(async callback => {
var prop = instance.data.myUsersList;

It doesn’t seem to make a difference either way in this case, but perhaps it might for bigger lists than I tested with, so I thought I’d mention it.

1 Like

Yes, loading the data into instance.data variables did the trick.
I didn’t make that inference after reading the docs for some reason.

Thanks Louis!

1 Like