Variable Within Repeat Not Recognized?

Hi TB Community!

I am trying to reference a variable that is within a "repeat" function. Please see below:
image
When I preview the snippet, it gives me the error below
image

I have checked the spelling multiple times. Also- This variable doesn't show up in the "sidebar" to be able to be selected.

I really appreciate any suggestions :grinning:

Hi!

It looks like there's a lot going on in the snippet, so it's a little hard to see what could be causing the issue. Could you share the snippet here (click the gear icon) or share it with me at dylan@blaze.today so I can take a look?

Sure thing! Inserted below:

{note}Property Type: {formmenu: default=; Single Family; Multifamily; name=tablepropertytype}{endnote}
{if: tablepropertytype="Single Family"; trim=yes}

Bed-Bath Count: Rental Rate: Expiration: {repeat: 1; locals=properties}{formmenu: default=3-Bed 1-Bath; 4-Bed 1-Bath; 5-Bed 1-Bath; 3-Bed 2-Bath; 4-Bed 2-Bath; name=tableunitmix} {note}{formmenu: default=Occupied; Vacant; name=multifamoccupancy}{endnote}{if: multifamoccupancy="Occupied"}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{else}{tablerentinfo="Vacant"}Vacant{endif} {if: multifamoccupancy="Vacant"}{tablerentexpiration="N/A"}N/A{endif}{note}{if: multifamoccupancy="Occupied"}{formmenu: default=Custom; Month-to-Month; name=tablerent; cols=10}{endif}{endnote}{if: tablerent="Custom"}{formtext: cols=10; name=tablerentexpiration}{endif}{if: tablerent="Month-to-Month"}{tablerentexpiration="M2M"}Month-to-Month{endif}{endrepeat} {endif}{note}{if: tablepropertytype="Multifamily"}Number of Units:{formmenu: default=; 2 Units; 3 Units; 4 Units; name=unitamount}{endif}{endnote}
{if: tablepropertytype="Multifamily"; trim=yes}{if: unitamount="2 Units"; trim=yes}

Unit Mix: Rent: Expiration: {repeat: 2; locals=properties}{formmenu: 1-Bed 1-Bath; default=2-Bed 1-Bath; 3-Bed 1-Bath; name=tableunitmix} {note}{formmenu: default=Occupied; Vacant; name=multifamoccupancy}{endnote}{if: multifamoccupancy="Occupied"}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{else}{tablerentinfo="Vacant"}Vacant{endif} {if: multifamoccupancy="Vacant"}{tablerentexpiration="N/A"}N/A{endif}{note}{if: multifamoccupancy="Occupied"}{formmenu: default=Custom; Month-to-Month; name=tablerent; cols=10}{endif}{endnote}{if: tablerent="Custom"}{formtext: cols=10; name=tablerentexpiration}{endif}{if: tablerent="Month-to-Month"}{tablerentexpiration="M2M"}Month-to-Month{endif}{endrepeat} {endif: trim=yes}{if: unitamount="3 Units"; trim=yes}

Unit Mix: Rent: Expiration: {repeat: 3; locals=properties}{formmenu: 1-Bed 1-Bath; default=2-Bed 1-Bath; 3-Bed 1-Bath; name=tableunitmix} {note}{formmenu: default=Occupied; Vacant; name=multifamoccupancy}{endnote}{if: multifamoccupancy="Occupied"}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{else}{tablerentinfo="Vacant"}Vacant{endif} {if: multifamoccupancy="Vacant"}{tablerentexpiration="N/A"}N/A{endif}{note}{if: multifamoccupancy="Occupied"}{formmenu: default=Custom; Month-to-Month; name=tablerent; cols=10}{endif}{endnote}{if: tablerent="Custom"}{formtext: cols=10; name=tablerentexpiration}{endif}{if: tablerent="Month-to-Month"}{tablerentexpiration="M2M"}Month-to-Month{endif}{endrepeat} {endif: trim=yes}{if: unitamount="4 Units"; trim=yes}

Unit Mix: Rent: Expiration: {repeat: 4; locals=properties}{formmenu: 1-Bed 1-Bath; default=2-Bed 1-Bath; 3-Bed 1-Bath; name=tableunitmix} {note}{formmenu: default=Occupied; Vacant; name=multifamoccupancy}{endnote}{if: multifamoccupancy="Occupied"}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{else}{tablerentinfo="Vacant"}Vacant{endif} {if: multifamoccupancy="Vacant"}{tablerentexpiration="N/A"}N/A{endif}{note}{if: multifamoccupancy="Occupied"}{formmenu: default=Custom; Month-to-Month; name=tablerent; cols=10}{endif}{endnote}{if: tablerent="Custom"}{formtext: cols=10; name=tablerentexpiration}{endif}{if: tablerent="Month-to-Month"}{tablerentexpiration="M2M"}Month-to-Month{endif}{endrepeat} {endif: trim=yes}{if: multifamoccupancy="Occupied"}***Please note: Current rents should not be used for future projections, with most properties, you would either attempt to raise the rent with the current tenant(s) or find new tenant(s) at market rate rents.{endif}

To add the snippet here in the community, you have to replace 'snippet contents' with your snippet by copying the commands in the snippet and pasting it where 'snippet contents' is in the text here.

I think the issue could be that the form field 'multifamoccupancy' is within the repeat command, and the if statement is outside of it.

Could you potentially move the form field + note command it is inside of to outside of the repeat command? Please let me know if that works.

1 Like

Okay copy that, I tried adding in the snippet to the text box multiple ways, but It didn't seem to save when I replied

I will play with putting it within the repeat function

Once you paste the contents of your snippet where it says 'snippet contents', you should see a preview of the snippet on the right side of the page where you preview your post.

If moving the form field doesn't work, please let me know and we can find another solution.

Ahhh gotcha okay, I just added the snippet contents to the left side, previously I was trying to add it directly to the right side. It is updated now :slight_smile:

Hi @ajduna7 ,
Because it's used within {repeat} there are multiple occurrences of the variable. To access them, use the locals setting:

{repeat: 3; locals=locals}
{formtext: name=field}{endrepeat}
{=locals[1].field}
{=locals[2].field}
{=locals[3].field}

Thanks Dan- I have tried all variations of the following snippet, and I can't seem to get it to work.

image

Currently I am getting the error: Unknown name "Locals"

Do you happen to have any other idea on how to structure this?

Just fyi- the name of my repeat function is "properties". The name of the variable I am trying to create an if/else command with is "multifamoccupancy"

Thank you

Hi! I took a look at your snippet, and tried a different approach.

{note}Amount of units: {formmenu: default=1; 2; 3; 4; 5; name=unitamount}{endnote}

Unit mix Rent Expiration {repeat: unitamount ; locals=properties}{formmenu: default=3-Bed 1-Bath; 4-Bed 1-Bath; 5-Bed 1-Bath; 3-Bed 2-Bath; 4-Bed 2-Bath; name=tableunitmix} {note}{formmenu: default=Occupied; Vacant; name=multifamoccupancy}{endnote}{if: multifamoccupancy="Occupied"}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{else}Vacant{endif} {if: multifamoccupancy="Vacant"}N/A{endif}{if: multifamoccupancy="Occupied"}{note}{formmenu: default=Custom; Month-to-Month; name=tablerent; cols=10}{endnote}{if: tablerent="Custom"}{formdate: YYYY-MM-DD}{endif}{if: tablerent="Month-to-Month"}Month-to-Month{endif}{endif}{endrepeat}
{if: contains(properties, "\"multifamoccupancy\": \"Occupied\"")}***Please note: Current rents should not be used for future projections, with most properties, you would either attempt to raise the rent with the current tenant(s) or find new tenant(s) at market rate rents.{endif}

image

Also another version:

{note}Amount of units: {note: preview=no}{formmenu: default=1; 2; 3; 4; 5; name=unitamount}{endnote}
{button: unitamount = 1
; label=1}{button: unitamount = 2
; label=2}{button: unitamount = 3
; label=3}{button: unitamount = 4
; label=4}{button: unitamount = 5
; label=5}{endnote}

Unit mix Rent Expiration {repeat: unitamount ; locals=properties}{note: preview=no}{formtoggle: name=Vacant; default=no}{endnote}{formmenu: default=3-Bed 1-Bath; 4-Bed 1-Bath; 5-Bed 1-Bath; 3-Bed 2-Bath; 4-Bed 2-Bath; name=tableunitmix}{if: Vacant = Yes}{button: Vacant = No
; label=↩ī¸}{else}{button: Vacant = yes
; label=đŸŸĸ}{endif} {if: Vacant = yes}Vacant{else}${formtext: cols=10; default={=replace(catch({site: text; page=https://now.mlsmatrix.com/*; select=ifneeded; selector=.multiLineDisplay .multiLineDisplay .multiLineDisplay .multiLineDisplay:nth-child(1) .d48m8 > .wrapped-field}, ""), "$", "")}; name=tablerentinfo}{endif} {if: Vacant = yes}N/A{else}{note: preview=no}{formmenu: Custom; default=Month-to-Month; name=tablerent; cols=10}{endnote}{if: tablerent="Custom"}{formdate: YYYY-MM-DD; name=expirationdate}{button: tablerent = "Month-to-Month"
; label=↩ī¸}{else}Month-to-Month{button: tablerent = "Custom"
; label=📅}{endif}{endif}{endrepeat}
{if: contains(properties, "\"vacant\": yes")}***Please note: Current rents should not be used for future projections, with most properties, you would either attempt to raise the rent with the current tenant(s) or find new tenant(s) at market rate rents.{endif}

image

3 Likes

Hi Ben! Thank you so much for crafting a few different variants, your second snippet introduced me to "buttons" I didn't realize those existed within Textblaze.

In this case I am actually looking to get a better idea of how to "phrase/format" the "locals" setting that Dan mentioned earlier. In order to reference a variable within a repeat function.

How would I go about creating an if/else for a variable within a repeat function? Thank you

1 Like

Hey Andrew! When you request the condition multifamoccupancy="Occupied" - do you mean to request it for each row of the table separately, or do you want to request that it be true for any row in the table?

Hi Guarang! Thanks for the speedy reply, I am hoping to have this text pop-up whenever, any row of the (repeat) table is marked as Occupied:

***Please note: Current rents should not be used for future projections, with most properties, you would either attempt to raise the rent with the current tenant(s) or find new tenant(s) at market rate rents.

I see. Can you try this then?

{if: count(filter(locals, x -> x.multifamoccupancy="Occupied"))>0}
Your text goes here
{endif}

Note that locals is a list containing one item for each of your rows. So if you have two rows, the locals list will look like this: [ { multifamoccupancy: "Value from row 1" }, { multifamoccupancy: "Value from row 2" }, ]. In my condition above, I filtered for rows that are occupied, and then made sure their count is more than zero.

Let me know if it works for you.

2 Likes

My man!! That worked perfectly!! The only thing I switched was "locals" to "properties" (the name of the repeat function)

Thank you so much! I love this software and the community

1 Like

Guarang- Another question for you sir!

Referencing the if/else you created (pasted below). If that text shows up, (the property is occupied at all). How would I send that info to Datablaze.

So for example: If the text shows up, because the property is occupied, how would I structure that / create a variable to be able to send a "yes" / "no" to a column named "occupied" in Datablaze?

Your previously created if/else:
{if: count(filter(locals, x -> x.multifamoccupancy="Occupied"))>0}
Your text goes here
{endif}

You can do it like so:

{occupied=count(filter(locals, x -> x.multifamoccupancy="Occupied")) > 0}
{if: occupied}
Your text goes here
{endif}

What I did here is to "lift" the condition (... > 0) into a separate variable assignment first (occupied = ), and then used that variable directly in my if condition (if: occupied) in place of the condition. You can now send this variable to Data Blaze as needed.

1 Like

Amazing! This worked perfectly. Thank you again :grinning: