How to return objects from plugins (SSA, CSA, Element Update & Element Workflow Actions)

@keith totally valid point. Interestingly enough though, you can use this method to communicate with other plugins/actions. I don’t have a good use case for you on that either but it is nevertheless possible.

2 Likes

I can’t even remember why I ever learned how to do this to be quite honest. It’s so convoluted. But something that can be done regardless. :man_shrugging:

1 Like

Yeah, I’m having a hard time thinking of practical applications of exposing plugin_a’s instance object to some other plugin_b. (Although doing so allows plugin_b access to a’s instance.triggerEvent() and instance.publishState() functions.)

It’d be a funky interface, but one could expose one plugin_a’s main properties object (the properties that is sent to initialize) on the window and then some other plugin of the same type could be made to inherit plugin_a’s settings (or some subset of settings). I had actually thought of doing this with (for example) Calendar Grid Pro, where the main interface has dozens of properties and it might be useful to just let the user plop another one on the page and, rather than making them copy/paste plugin_a or fill out dozens of fields, they could just fill in a text field that’s plugin_a’s HTML ID to say “this one looks just like that one”.

Hi, I am trying to return an array of object from server side action but it’s returning empty array. If I fill up the array manually it works fine as you showed in the video but when I am filling up that array after reading data from bubbles database and doing some operations on those datatable it doesn’t work. Also if I console.log() it in the client side action It’s working fine. Don’t know what I’m doing wrong, any help is appreciated.

Here is my code: JSFiddle - Code Playground
Return data model:

Output data setting:

Output empty array in server side action:
pluginOutput

I managed to return the object from the server side action. But is there any way I can treat it as my custom type in the following steps of my workflow?
image
At the moment that’s the only thing that shows when I try to create a list of things from the previous step.

However, when I set the previous step return type to my actual data type, it shows as expected “allowing me to directly add it to my database”
image

You can do it by creating a script that changes the JavaScript array and you can make an action to change one of the objects in those arrears but you can’t do it with bubbles native workflow actions.

If it works when you manually fill out the array, but not after processing data than your incorrectly, creating the array, or creating an array with invalid values. I would recommend returning the array as a string to the client side so that you can inspect what you’re actually trying to publish as an array of things.

Hi,
Impressed by your work, and all talks around here. Really helped me. However, I am stuck on something stupid I guess, trying to implement Returning an object from a plugin element’s update field.

Context :
I am creating a Plugin. In it, I am creating an Element.
In the Field, I am creating an App Type called data_type and exposing a state called items with this data_type as Type. cf picture

In the API connector, I define a new endpoint “GET tags_custom”, and I manually define its output

Then I test it with this definition

However, all I can see when running it in debug mode is an empty object. And I have no clue where it came from. Tried many things in vain.

Here is my initialize function dealing with this item publishState . Note that in my update funciton, I simply call this data.testPublish() to make the call every time :

I tried to prefix string, boolean and number with “p” or “api” just in case but didn’t work

Any clue ?

While writing the question I found out that adding “api_c2” solved the problem. I kept the post in case someone else stumble upon the same issue !

1 Like

I’m having to call the action twice so I can call the state on another object.

It´s Normal?

How do you mean

1 Like

Hello @jared.gibb

I’m using this code

function(instance, properties, context) {
    const element = document.getElementById(properties.id_element)
    const img = element.querySelector('img');
    const imageAnonymous = new Image();
    imageAnonymous.src = img.getAttribute('src');
    imageAnonymous.crossOrigin = "Anonymous";
    imageAnonymous.width = img.width;
    imageAnonymous.height = img.height;

    async function receive() {
        let list = [];
        const detection = await faceapi.detectSingleFace(imageAnonymous).withFaceLandmarks().withFaceDescriptor();
        if (detection) {
            list.push(detection.descriptor);
        } else {
            console.log('No face detected');
        }
        return list;
    }

    receive().then((result) => {
            window.myinstance.publishState('faceid_one', JSON.stringify(result[0]));
        
    });
}

it is updating the status of the element normally, but I can only use it if I call the function again

EDIT1
Here I called the action once

here I called her the second time


my workflow is like this
image

Not sure why I have to call twice to update my status. is it a bug?

Sorry for my bad english, I’m using google translator

loading images is an async operation. your code treat it like if it was synch. the first time you invoke the action nothing happens because the image is still loading.

2 Likes

Hi @dorilama ,
Thanks for answering me.

But I’m just calling the action after clicking the button and the image is loaded. Do you have a connection?

EDIT1

the status is available in my element, as shown in the first image, I just can’t access it right away.

I think you have 2 problems:

  • assigning a src to a HTMLImageElement starts loading the image asynchronously, on the next line the image can be loaded or not, you need to use the load event to be sure.
  • using async code in bubble plugins without context.async means that bubble can’t monitor the execution of your code. The next action in the workflow will run without waiting for your async function. Either you use context.async or you need to trigger an event at the end of your async code and split your workflows in bubble: one workflow with actions up to your plugin’s action and a second part triggered by your plugin’s event with the rest of your logic.
2 Likes

Thanks for the guidance… I was able to resolve the error by adding an action to the element.

I saw this answer here on the forum and after testing it, it worked

1 Like

Hi @jared.gibb,

I am trying to develop a plugin to get back the folder path of the current folder.
Each folder as a field in the database called parentFolder. When we reach the root folder that has not parent we stop the function and return the list with all the folders. I will use this list to display all the folder path.
I always get an error, maybe you could tell me what I am doing wrong.
Thanks for your help

And this is the function that runs when Get path is called

function(instance, properties, context) {

  let currentFolder = "selectedfolder";
  const folderPath = [];

  while (currentFolder.parentFolder !== null) {
    folderPath.push(currentFolder);
    currentFolder = "thing".data[currentFolder.parentFolder.uniqueid];
  };

  folderPath.push(currentFolder);
  folderPath.reverse();
  instance.publishState("path", folderPath);
  
}

Dude, you’re defining currentFolder as a string. So why would it have a parameter .parentFolder on it? (It wouldn’t.)

EDIT: you can retrieve a Thing type field that refers to something that is conceptually “above” some folder Thing, but you need to get its field values first (using the .get() method on Things). You don’t just reference them as “dot something”.

The approach you’d need to take here, even if you had a basic understanding of JavaScript and the Bubble plugin API, would be to send the ALL the folders, just like I do in the no-code List Shifter example I sent earlier.

Also, where are you getting this absolutely nonsensical code? Oh, let me guess…

4 Likes

I can’t understand it at all, but I chalked it up to me being illiterate.

Educate us here, what is wrong with it? Is it ChatGPT hallucinating?

2 Likes

you figure out your issue yet? cause this thread isnt the solve for your issue im guessing BUT we can try to work thru things :wink: