When can you use property.subproperty notation?

Hi, I have something slightly odd happening and I think it’ll be good for me to know why it’s occurring.

Consider this codeless:

I have an object, “employeeRecord” that has many properties. I can access these in data bindings and other places using notation like employeeRecord.address, employeeRecord.city, etc.

In the block above though, my Set Property In blocks are not consistently overwriting the existing properties. Sometimes they are creating new properties instead. See employeeRecord.googleFormattedAddress, .googlePlaceId, and .zipcode as an example.

Can you help me understand why this happens? I can work around this using Get Property Of blocks but it’ll be good to know when the . notation can work.

Thanks!

As a follow-on, let’s say that I successfully work around the issue above by just using a bunch of Get Property Of blocks like this:

Two questions:

  1. Could I have created a variable called “employeeRecord”, gave it the value of Get Property “employeeRecord” of “formEditProfile” Data, and then just used that in the “Set Property In” field of each block? (Just to reduce the get property of calls and make it a bit more readable)

  2. Is there a more elegant way to handle a situation like this where I have the same block repeating over and over again but there’s a slight difference each time? I think I might have been able to use a custom function but I don’t quite see how to set it up so that it gets the different ‘contains item’ string each time.

Thanks!
James

  1. Yes, you could.
    image
    image

  2. You can create a Custom Function and use popular native solution

var pList = path.split('.');
var len = pList.length;
for(var i = 0; i < len-1; i++) {
    var elem = pList[i];
    if( !schema[elem] ) schema[elem] = {}
    schema = schema[elem];
}

schema[pList[len-1]] = value;

As result you should get something like that

image

Thanks @Dima . I think this solution could work for the questions I had in the follow-on reply. I will be mainly interested in using the codeless approach. Can you point me to where the “Set _____ to” block is located? The one where you use for “set nestedObject to” and “set nestedProp to”. I am unfamiliar with those and can’t find them in the codeless blocks.

@vladimir-upirov the first message in this thread is the other example of the behavior I sent over in slack.

Thanks!

In Variables group from right menu with codeless blocks

Ah, thank you. I should have looked there. Thanks!