Output an object for server-side/client-side

Ok am trying this and will get back… thank you again

1 Like

Hi,

Its works!!! :smile: You were right about the super-hack to create a “custom output object”… then using the p notation to make the JSON object does the trick. I thought step 2 was for server side, but I see it is the hacky-step to create a custom object for output that can be used with the instance.Publish state

Thank you very much for your time to help me understand this work-around-hack :slight_smile:

2 Likes

A bit late to this, and brand new to Bubble, but why hasn’t Bubble simply made custom data types available in the plug in editor?

Every instruction in this list works for me, except the very last one, where I do not see the Plugin Action as a valid selection within a workflow action.

I even went so far as to recreate this Test action identically.

The funny thing is this Plugin already has one action that I do see, but this action I do not.

Any idea what critical step I’m missing?

Later edit: It appears I was merely impatient. I took a 30 minute break, and when I returned, the “missing” Plugin Actions were no longer missing.

intéressant

Can you define more than one custom type ? As there is no way to identify them in the action, I assume no.

You need to add additional API calls to achieve that.

Hello everyone,

I want to let you know that I’ve published the following package:

In short, it may help simplify Step 3 if you have a complicated or large object to prepare.

Let me know if you have any questions, please.

Stay safe!

6 Likes

@lottemint.md does this work for client side plugins as well? can you share an example?

1 Like

It looks like you figured it out how to use that since you sent a PR for that repository.
Thanks for catching that issue!

Let me know if you have any questions, please.

BTW, as I remember, there was an issue sending a null date to an API endpoint. I’ll recheck that.

Just in case any other plug-in devs might find it useful…

Thanks, @lottemint.md!

3 Likes

Can someone please rescue me?

I’ve followed through all the steps.
I checked my results using console.log with the same code on client-side, and this is what i get:
[{_p_attribute_id_number:1600000,_p_attribute_text_text:"Storage Type",_p_value_text_text:"eMMC",_p_category_text_text:"Key Specs",_p_numerical_value_number: null,_p_value_id_number:1600004,_p_model_text:"XE350XBA-K01US"},{_p_attribute_id_number:2400000,_p_attribute_text_text:"Graphics",_p_value_text_text:"Intel UHD Graphics 600",_p_category_text_text:"Key Specs",_p_numerical_value_number: null,_p_value_id_number:2400002,_p_model_text:"XE350XBA-K01US"},{_p_attribute_id_number:1100000,_p_attribute_text_text:"Operating System",_p_value_text_text:"Chrome OS",_p_category_text_text:"Key Specs",_p_numerical_value_number: null,_p_value_id_number:1100003,_p_model_text:"XE350XBA-K01US"},{_p_attribute_id_number:1200000,_p_attribute_text_text:"Memory",_p_value_text_text:"4 gigabytes",_p_category_text_text:"Memory",_p_numerical_value_number:4,_p_value_id_number:1200007,_p_model_text:"XE350XBA-K01US"}]

If I simply set my return value manually to the text above, it works like a charm, but when I pass it as a variable it returns null values.

Can you show the actual code usage please?

Sure.
My code receives a multiline text and turns it into an array.
for example:

- Key Specs
1600000;Storage Type;eMMC;;1600004
2400000;Graphics;Intel UHD Graphics 600;;2400002
1100000;Operating System;Chrome OS;;1100003
- Memory
1200000;Memory;4 gigabytes;4;1200007

This array is parsed into an array of objects.

function(properties, context) {

//Load any data 
var text = properties.specs_text;
var model = properties.model;
var array = text.split("\n");;
var response = '';
 var resarray = [];
var current_category = "";
for (var i=0;i<array.length;i++)
{
    var header = array[i].match(/^-\s(.*)/);
    if (header !== null)
    {
        current_category = header[1];
    }
    else
    {
        var specs = array[i].match(/(.*);(.*);(.*);(.*);(.*)/);
        if (specs !== null) {
               resarray.push( {
             	_p_attribute_id_number: specs[1],
             	_p_attribute_text_text: specs[2],
           	 	_p_value_text_text: specs[3],
            	_p_category_text_text: current_category,
           		_p_numerical_value_number: specs[4],
            	_p_value_id_number: specs[5],
            	_p_model_text: model
            });
        } 
    }
}

response = JSON.stringify(resarray);
       //Regex to remove double quotes from properties
response = response.replace(/"([^"]+)":/g, '$1:');
   // Regex to remove double quotes from numbers
response = response.replace(/:\s*"(\d+)"/g, ':$1');
// Regex to turn empty string to null
response = response.replace(/:"",/g, ': null,');


return { "response": response }

}

My results is (Out of console.log when testing with client side using the same code):

[{_p_attribute_id_number:1600000,_p_attribute_text_text:“Storage Type”,_p_value_text_text:“eMMC”,_p_category_text_text:“Key Specs”,_p_numerical_value_number: null,_p_value_id_number:1600004,_p_model_text:“XE350XBA-K01US”},{_p_attribute_id_number:2400000,_p_attribute_text_text:“Graphics”,_p_value_text_text:“Intel UHD Graphics 600”,_p_category_text_text:“Key Specs”,_p_numerical_value_number: null,_p_value_id_number:2400002,_p_model_text:“XE350XBA-K01US”},{_p_attribute_id_number:1100000,_p_attribute_text_text:“Operating System”,_p_value_text_text:“Chrome OS”,_p_category_text_text:“Key Specs”,_p_numerical_value_number: null,_p_value_id_number:1100003,_p_model_text:“XE350XBA-K01US”},{_p_attribute_id_number:1200000,_p_attribute_text_text:“Memory”,_p_value_text_text:“4 gigabytes”,_p_category_text_text:“Memory”,_p_numerical_value_number:4,_p_value_id_number:1200007,_p_model_text:“XE350XBA-K01US”}]

This is what i get when using manually (Chrome’s inspect):

And this is what I get when using my variable:

So you’re trying to create a server-side action? Is that right? And you’re saying that if you use the same code client-side, it works, but it doesn’t work server-side?

If that’s the case, are you fetching the data asynchronously server-side? Bubble provides a function specifically for that. Sounds like it might be a case of your code is running without waiting for the return value.

-Steve

Yes, it’s a server-side action. and yes, for some reason on the server-side it doesn’t work.
I don’t know if I’m working asynchronously or not, how do I verify?
What do i need to do to make it work? :hot_face:

What is properties.specs_text? It looks like you’re just parsing a text field?

Have you tried just stepping through the code client-side using some sample data?

properties.specs_text
is indeed a text input of which my code processes.
I did execute the code on the client-side and it outputs to console.log successfully as intended.

I might be missing something obvious (and this might be a bit of a side track), but what’s the advantage of a server-side script if the text being processed is being input directly by the user?

Then I’m not sure what you mean when you say it doesn’t work “when using my variable”. Did you step through - not just execute - the code when it provides incorrect ouput?