add current item in forloop + global forloop reference (#2512)

This commit is contained in:
Shuchang Zheng
2025-05-29 08:12:07 -07:00
committed by GitHub
parent 49ef1aaa07
commit bd72491d7d
4 changed files with 29 additions and 0 deletions

View File

@@ -198,6 +198,15 @@ class Block(BaseModel, abc.ABC):
)
template_data[self.label] = block_reference_data
# inject the forloop metadata as global variables
if "current_index" in block_reference_data:
template_data["current_index"] = block_reference_data["current_index"]
if "current_item" in block_reference_data:
template_data["current_item"] = block_reference_data["current_item"]
if "current_value" in block_reference_data:
template_data["current_value"] = block_reference_data["current_value"]
return template.render(template_data)
@classmethod
@@ -948,7 +957,9 @@ class ForLoopBlock(Block):
metadata: BlockMetadata = {
"current_index": loop_idx,
"current_value": loop_over_value,
"current_item": loop_over_value,
}
workflow_run_context.update_block_metadata(self.label, metadata)
workflow_run_context.update_block_metadata(loop_block.label, metadata)
original_loop_block = loop_block

View File

@@ -8,6 +8,8 @@ from pydantic import BaseModel, ConfigDict, Field
from skyvern.exceptions import InvalidWorkflowParameter
RESERVED_PARAMETER_KEYS = ["current_item", "current_value", "current_index"]
class ParameterType(StrEnum):
WORKFLOW = "workflow"