Insert property in object of weweb variable with javascript

In a workflow when I make a partial update and set the path to a new property (which is also in a new nested object) and it adds the object and the property.

I tried to do the same in javascript but failed:

variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’][‘test’]=“test”;

Cannot read property of undefined.

After the object structure exists the javascript works but it does not create the objects and properties. So what is partial update doing under the hood?
Something more complex?

1 Like

O, nice request. Where did you find the info about fall updates? Wanna read.

Sorry for that I am creating a german app and fall in German means “Case”. It is a legal tech company… is just an example.

But wait until wednesday. I am very keen what they will present. The reworked the editor…

The new editor wont change the fact that what you’re doing goes against JS rules I guess.

The editor probably makes some sort of checks, or via some utility creates the missing properties of the object.

You can do something like in this stack overflow answer

I would stage:

// Step 1 - make sure fall exists and initialize to a blank object if not
if(!variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’]) variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’] = {}; 
// Step 2 - make sure the case exists andset it to a blank object if not
if(!variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’]) variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’] = {}
// Step 3 - update the test variable
variables[/* fall_updates */‘3d4de373-5b9a-48ee-8b56-8955b668b341’][‘fall’][‘ff40c4fe-c410-4ae1-96ba-bcaea61a2f58’][‘test’]=“test”;

Thank you so this is the way to go and the internal action will probably do it as well =)
ok.

Just hoped to find a dynamic way where I can create properties of object nested in infinity levels. But to get this into a loop seems not so easy…

I think we use the set method from lodash Lodash Documentation

Thought so. Lodash instance is also accessible in the browser, isn’t it?

Yes but it includes only the methods we use. I don’t recommend to use them as we could remove lodash at some point and it will not work anymore.

Capture d’écran 2023-12-04 à 16.09.08

Hmm… understood…

Than there is no save way to do the partial update with automatic object path creation with javascript?

You could use the npm plugin to add lodash that way. I haven’t confirmed this would work- only some npm packages do. I made a video on using the npm functionality with weweb:

I’m not sure, because it might conflict with WeWeb’s lodash. I’ve tried to import supabase v2 like this.

I checked - the lodash.set npm package will successfully import a window function called “set” that is the lodash set function. I looked at it in the editor - it does not appear to conflict with weweb internals.

1 Like

Thank you very much raydeck!
I will go this route…