First retrieve a list of “things” via properties.list_of_bubble_things.get(0, properties.list_of_bubble_things.length())
Then, I’m attempting to do a .forEach on every single one of those objects, to retrieve a data field for every single bubble object.
Example code -
var things = properties.list_of_bubble_things.get(0, properties.list_of_bubble_things.length());
things.forEach(element, index){
var field = element.get('field_name');
//more code that uses the above field variable
});
Issue is, the field variable is always equal to null, as the function hasn’t loaded that data yet.
Also, to specify, this field I’m attempting to use is a date range, and isn’t a link to another data type.
I’m assuming this can be fixed using an async function, but i’m not too familiar with how to do that, especially since the async function must be called for each bubble object, then rest must be executed when all values are loaded.
Also, just to note, this is a server side action. Everything works perfect client side.
//This code get the list as an object which you can then iterate over
let objToFetch = properties.list.get( 0, properties.list.length());
//Use this code if you need to examine the object length
console.log('objToFetch',objToFetch.length);
//Get and add variables to plugin
objToFetch.forEach(e => {
let n = e.get(properties.variable_names);
let v = e.get(properties.variable_values);
//use this code to examine the results console.log('Variable Added','Vartiable Name:',n,'Variable Value:',v);
});
This is normally fine for me, per @AliFarahat 's method.
To me it looks as though your use of forEach has an error in it.
The syntax should be: *your-array*.forEach((item, index) => {*your function code*});
I think you are missing an ( after forEach and an arrow function => after the parameters… to it would read: things.forEach((element, index) => { *** })
You might have already worked this out after seeing the example above.
Thanks for the replies @exception-rambler@AliFarahat . I don’t think that is the issue here, as I have it running with my syntax on a client side element.
*your-array*.forEach((item, index) => {*your function code*}); is the shorthand version of my forEach function.
I’m working on a server side action since I need to be able to run this plugin on the backend. Also the issue doesn’t seem to be on loading the data at this part
var things = properties.list_of_bubble_things.get(0, properties.list_of_bubble_things.length());
It seems to be when trying to access a field from here like so.
var thing = properties.list_of_bubble_things.get(0, properties.list_of_bubble_things.length())[x].get('fieldname'); as this will return null as it hasn’t been loaded by the server yet.