How does a plugin return multiple values?

I’m writing a plugin that does some simple object and string manipulation. The code is below.

I’m not sure of the syntax of how to return the object I’m returning.

Here is the documentation shown within the Action code section:

I’m not sure how to know the name of the object being returned.

Below is the javascript. The console.log statements are a carry over from where I mocked this up outside of Bubble, and I ran it client side action before I switched it to server side action.
function(properties, context) {
console.log(“makeObjectGeneric: Executing”)

// Get input
let objectText = properties.objectstring
let emailAddr  = properties.emailaddrinput
console.log("makeObjectGeneric: objectText", objectText)
console.log("makeObjectGeneric: emailAddr",  emailAddr)

// Turn objectText into objectParsed
let objectParsed = JSON.parse(objectText)

// Change the name of the key to the more generic one
let oldKey = emailAddr
let newKey = "emailAddress"
Object.defineProperty(objectParsed, newKey, Object.getOwnPropertyDescriptor(objectParsed, oldKey))
delete objectParsed[oldKey]
console.log("makeObjectGeneric:objectParsed", objectParsed)

// Console.log the object values
console.log("success: ",           objectParsed.success)
console.log("email: ",             objectParsed.emailAddress.data.email)
console.log("isDisposable: ",      objectParsed.emailAddress.data.isDisposable)
console.log("isGibberish: ",       objectParsed.emailAddress.data.isGibberish)
console.log("isValidFormat: ",     objectParsed.emailAddress.data.isValidFormat)
console.log("isWebmail: ",         objectParsed.emailAddress.data.isWebmail)
console.log("smtpStatus: ",        objectParsed.emailAddress.data.smtpStatus)
console.log("statusIdentifier: ",  objectParsed.emailAddress.status.identifier)
console.log("statusDescription: ", objectParsed.emailAddress.status.description)

console.log("makeObjectGeneric: Exiting")

return

}

I’ve tried three different return statements:

return objectParsed: Generated an error message saying: the key emailAddress is not part of the value definition

return: Does not generate any error messages, and every “field” I want is accessible via a “Result of step X” value when I create a DB record immediatly after the plugin action runs, but the DB fields are blank.

// return: Same as the the return statement being executed with no argument

So, I understand I’m returning an object, I’m just not sure I know what it’s called or how to properly do so.

Can anyone help me?

Hello Kevin, see this post

1 Like

That is seriously convoluted.

Is there possibly a way of using Element:Actions rather than Actions?

With them I can publish states and trigger events. Can I possibly publish multiple states then trigger one event?

1 Like

For what it’s worth, building a plugin that uses Element:Actions rather than Actions does work. It does require creating a visual element that is never shown on the page, but it’s much less convoluted than the workaround described above.

Hey @kevin4,

The workaround linked above is for returning an actual custom data type you have defined in your app.

To return the individual values just return the object exactly as shown and replace the values with the correct values.

Here’s a small example that can be extrapolated out.

return {
emailaddr: objectParsed.emailAddress.data.email,
isDisposable: objectParsed.emailAddress.data.isDisposable
}

Try this.
Make sure you have an exposed state available “exposed_state” for example

In your initialize function, add this this

//initialize the variable dataToReturn. You’ll access it using the path below. 

instance.data.dataToReturn = “test”;

In your element action function add

var data = instance.data.dataToReturn;
publishState(“exposed_state”, data);

This makes sense. It’s too bad I didn’t think of it earlier, before I changed over to the Element:Action type of plugin.