From aaae087e2e96483baa9128a7c72a803d5e5a262c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cjdattatr-tibco=E2=80=9D?= <“jdattatr@tibco.com”> Date: Fri, 7 Jun 2024 11:24:08 +0530 Subject: [PATCH] Add functionality to access index value while iterating over primitive array --- data/resolve/loop.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/data/resolve/loop.go b/data/resolve/loop.go index 2e6fdc98..93c6c2a0 100644 --- a/data/resolve/loop.go +++ b/data/resolve/loop.go @@ -16,7 +16,7 @@ func (*LoopResolver) GetResolverInfo() *ResolverInfo { return loopResolverInfo } -//LoopResolver Loop Resolver $Loop[item] +// LoopResolver Loop Resolver $Loop[item] func (*LoopResolver) Resolve(scope data.Scope, item string, field string) (interface{}, error) { var value interface{} var exist bool @@ -25,6 +25,13 @@ func (*LoopResolver) Resolve(scope data.Scope, item string, field string) (inter if !exist { return nil, fmt.Errorf("failed to resolve current Loop: '%s', ensure that Loop is configured in the application", field) } + } else if item == "index" { + //To access the index value eg: $Loop[index] + value, exist = scope.GetValue("_loop") + if !exist { + return nil, fmt.Errorf("failed to resolve current Loop: '%s', ensure that Loop is configured in the application", field) + } + return path.GetValue(value, ".index") } else { value, exist = scope.GetValue(item) if !exist {