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?