Skip to content

Empty value in parent variable on nested repeat block #706

@255kb

Description

@255kb

Discussed in #704

Originally posted by neofly May 5, 2022
Hello,

I'm using nested repeat blocks in a JSON Response template having the nested block using a parent variable {{@itemId}}.

{
	"items": [
	{{#repeat (faker 'random.number' min=1 max=5)}}
		{{setVar 'itemId' (faker 'random.uuid')}}
		{{setVar 'itemParts' (int 1 4)}}
		{
			"id": "{{@itemId}}",			
			"active": true,
			"type": "TYPE",
			"parts": [
			  {{#repeat @itemParts}}
				{
					"id": "{{faker 'random.uuid'}}",
					"quantity": {{faker 'random.number' min=1 max=4}},
					"parent": "{{@itemId}}",
				}
			  {{/repeat}}
			]
		}
	{{/repeat}}
	]
}

The problem is that the {{@itemid}} in the nested block returns an empty value :

{
    "items": [
        {
            "id": "5f0899d0-bfc5-4b3b-9532-9b3fca2bcaba",
            "active": true,
            "type": "TYPE",
            "parts": [
                {
                    "id": "f2e9354e-4877-4372-9ab1-2667e08fc28b",
                    "quantity": 1,
                    "parent": "",
                },
                {
                    "id": "f4807b63-d367-4529-a109-908126b65f86",
                    "quantity": 2,
                    "parent": "",
                },
                {
                    "id": "d4d5d884-a40a-4b4e-82d9-63060b58ee4d",
                    "quantity": 1,
                    "parent": "",
                },
                {
                    "id": "0e1ac766-b31d-469c-9e80-def95a881f53",
                    "quantity": 3,
                    "parent": "",
                }
            ]
        }
    ]
}

Am I doing something wrong ? Or this may by an issue ?

Thanks

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done (ready for next release)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions