No way to read form fields from the payload?

Question:
is there no way to read form fields from the payload in velo script?

Product:
Wix Studio Editor

What are you trying to achieve:
i can select forms payload elements with invoke method, but no fields with payload syntax. for example i can select ‘formName’ by invoke ‘payload.formName’, but I also need sam form-field-value. There is a payload for testing and the form fields are all available as ‘field:fieldID’ , but I have not found a correct method to read the ‘field:fieldID’ values by invoke method ((the form-field-values are all looks like “field:fieldID” in the payload with a colon between field and fieldID).

What have you already tried:
I try to invoke a form-field element with different methods. However, I have not found a way to get the field:values ​​in my Velo background script.

The Payload with the example Data from the Form
{
“formName”: “My form”,
“submissions”: [ { “label”: “label”, “value”: “value” } ],
“submissionTime”: “2018-11-13T20:20:39+00:00”,
“formFieldMask”: [ “Maskname” ],
“submissionId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“contactId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“submissionsLink”: “https://www.wix.app/forms/0d3de181-9309-47d3-bb2d-97147e96679b/submissions?metaSiteId=7686c703-b77b-4747-817b-1f25fcd53791”,
“formId”: “0d3de181-9309-47d3-bb2d-97147e96679b”,
“field:anmerkung”: “field:anmerkung”,
“field:betreungszeit”: “field:betreungszeit”,
//and so on…
}

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

Hello,
When you are working with form submissions and payload data, reading form field values that are stored in a format like field:fieldID is a bit tricky. The issue here is that you’re trying to access these field values using the payload’s field syntax (field:fieldID), but Velo scripts typically do not directly support reading these fields using that specific notation with a colon.

Solution 1: Accessing Form Field Values
To extract the values of form fields from the payload, you can access the submissions object which typically contains the form data. Your payload looks like this:

{
“formName”: “My form”,
“submissions”: [
{ “label”: “label”, “value”: “value” }
],
“submissionTime”: “2018-11-13T20:20:39+00:00”,
“formFieldMask”: [ “Maskname” ],
“submissionId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“contactId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“submissionsLink”: e-zpassma
“formId”: “0d3de181-9309-47d3-bb2d-97147e96679b”,
“field:anmerkung”: “Sample value”,
“field:betreungszeit”: “Sample value 2”
}
You can access the form fields and their values using the correct object structure by referencing them directly. For example:

let payload = {
“formName”: “My form”,
“submissions”: [
{ “label”: “label”, “value”: “value” }
],
“submissionTime”: “2018-11-13T20:20:39+00:00”,
“formFieldMask”: [ “Maskname” ],
“submissionId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“contactId”: “edca2245-7ce3-4d95-bfe9-b2012110eb8f”,
“submissionsLink”:
“formId”: “0d3de181-9309-47d3-bb2d-97147e96679b”,
“field:anmerkung”: “Sample value”,
“field:betreungszeit”: “Sample value 2”
};

// Using direct field access
let anmerkungValue = payload[“field:anmerkung”];
let betreungszeitValue = payload[“field:betreungszeit”];

console.log(anmerkungValue); // Output: Sample value
console.log(betreungszeitValue); // Output: Sample value 2
This approach works because JavaScript allows you to access keys with special characters (such as the colon :slight_smile: using bracket notation. The colon in the field names doesn’t interfere when you use this format.

Solution 2: Iterating Over Payload Keys
If you are not sure what the field IDs are, you can iterate over the keys in the payload to identify the fields dynamically. Here’s how you can do it:

for (let key in payload) {
if (key.startsWith(“field:”)) {
console.log(Field: ${key}, Value: ${payload[key]});
}
}
This will print out the values for all fields with keys that start with field:. It can help you dynamically access all form fields, regardless of their specific IDs.

Solution 3: Using invoke (If Required)
If you are using the invoke method, you need to ensure that the correct object is being referenced. For example, you can use invoke to dynamically access properties. Here’s an example of how to invoke the form fields:

$w.onReady(function () {
// Assuming ‘payload’ is passed to this context
let fieldValue = invoke(payload, ‘field:anmerkung’);
console.log(fieldValue);

// ‘invoke’ function implementation could look like this:
function invoke(obj, field) {
return obj[field];
}
In the invoke method, you’re passing the key of the form field, and the method returns the corresponding value.

Best Regard,
Emily