Expression evaluation error at function 'localvariables': LocalVariables expects final parameter to be its result value, not a definition of local variable 'local!

Certified Senior Developer

a!localVariables(
  /*
    1 - requestId, 2 - Department, 3 - Sub Department, 4 - Requestor, 
    5 - Status, 6 - Ship Name, 7 - Task Status
  */
  local!inputList: split(ri!input, "#$"),
  local!requestId: tointeger(local!inputList[1]),
  local!deptIdList: tointeger(split(local!inputList[2], "-$-")),
  local!subDeptIdList: tointeger(split(local!inputList[3], "-$-")),
  local!requestor: touniformstring(split(local!inputList[4], "-$-")),
  local!shipId: tointeger(local!inputList[6]),
  local!statusIdList: touniformstring(split(local!inputList[5], "-$-")),
  local!taskStatus: toboolean(local!inputList[7]),
  local!result: a!flatten(
  a!forEach(
    items: enumerate(5),
    expression: a!localVariables(
      local!batchSize: 2000,
      local!startIndex: if(
        tointeger(fv!index) = 1,
        1,
        1 + ((fv!index - 1) * local!batchSize)
      ),
      /*rule!BUS_QE_getBUSReqViewDetails, BUS_QE_getBUSReqVWDtlsTest*/
      rule!BUS_QE_getBUSReqVWDtlsTest(
    fetchtotalcount: true,
    selection:{"id",
    "stateroomRequestId",
    "deptName",
    "subDeptName",
    "requestedOn",
    "requestedBy",
    "reasonType",
    "shipName",
    "status",
    "pendingSailDates",
    "bookedSailDates"},
    filters: {
      a!queryFilter(
        field: "stateroomRequestId",
        operator: "not null"
      ),
      a!queryFilter(
        field: "stateroomRequestId",
        operator: "=",
        value: local!requestId,
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(inputValue: local!requestId)
        )
      ),
      a!queryFilter(
        field: "deptId",
        operator: if(
          or(
            rule!APN_isEmpty(local!deptIdList),
            length(local!deptIdList) = 1
          ),
          "=",
          "in"
        ),
        value: if(
          or(
            rule!APN_isEmpty(local!deptIdList),
            length(local!deptIdList) = 1
          ),
          tointeger(local!deptIdList[1]),
          tointeger(local!deptIdList)
        ),
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(local!deptIdList)
        )
      ),
      a!queryFilter(
        field: "subDeptId",
        operator: if(
          or(
            rule!APN_isEmpty(local!subDeptIdList),
            length(local!subDeptIdList) = 1
          ),
          "=",
          "in"
        ),
        value: if(
          or(
            rule!APN_isEmpty(local!subDeptIdList),
            length(local!subDeptIdList) = 1
          ),
          tointeger(local!subDeptIdList[1]),
          tointeger(local!subDeptIdList)
        ),
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(local!subDeptIdList)
        )
      ),
      a!queryFilter(
        field: "status",
        operator: if(
          or(
            rule!APN_isEmpty(local!statusIdList),
            length(local!statusIdList) = 1
          ),
          "=",
          "in"
        ),
        value: if(
          or(
            rule!APN_isEmpty(local!statusIdList),
            length(local!statusIdList) = 1
          ),
          touniformstring(local!statusIdList[1]),
          touniformstring(local!statusIdList)
        ),
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(local!statusIdList)
        )
      ),
      a!queryFilter(
        field: "requestedBy",
        operator: if(
          or(
            rule!APN_isEmpty(local!requestor),
            length(local!requestor) = 1
          ),
          "=",
          "in"
        ),
        value: if(
          or(
            rule!APN_isEmpty(local!requestor),
            length(local!requestor) = 1
          ),
          touniformstring(local!requestor[1]),
          touniformstring(local!requestor)
        ),
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(local!requestor)
        )
      ),
      a!queryFilter(
        field: "shipId",
        operator: "=",
        value: local!shipId,
        applyWhen: not(
          rule!CMN_checkNullOrEmpty(local!shipId)
        )
      ),
      a!queryFilter(
        field: "taskStatus",
        operator: if(local!taskStatus, "not null", "is null"),
        applywhen: if(isnull(local!taskStatus), false, true)
      )
    },
    paginginfo: a!pagingInfo(startIndex: local!startIndex, batchSize: local!batchSize)
  ).data
  )
  )
  ),
  local!finalResult: a!forEach(
    items: local!result,
    expression: 'type!{urn:com:appian:types}BUS_RequestViewDetail'(
      reportId: fv!item.reportId,
      stateroomRequestId: fv!item.stateroomRequestId,
      id: fv!item.id,
      requestedBy: fv!item.requestedBy,
      requestedOn: fv!item.requestedOn,
      deptId: fv!item.deptId,
      subDeptId: fv!item.subDeptId,
      subDeptName: fv!item.subDeptName,
      status: fv!item.status,
      reasonTypeId: fv!item.reasonTypeId,
      reasonType: fv!item.reasonType,
      shipId: fv!item.shipId,
      shipName: fv!item.shipName,
      deptName: fv!item.deptName,
      taskName: fv!item.taskName,
      taskDisplayName: fv!item.taskDisplayName,
      taskStatus: touniformstring(
        index(
          index(
            ri!taskHistory,
            wherecontains(
              tointeger(fv!item.stateroomRequestId),
              tointeger(
                index(ri!taskHistory, "requestId", null)
              )
            ),
            null
          ),
          "taskStatus",
          null
        )
      ),
      assignedTo: if(
        rule!APN_isEmpty(
          touniformstring(
            index(
              index(
                ri!taskHistory,
                wherecontains(
                  tointeger(fv!item.stateroomRequestId),
                  tointeger(
                    index(ri!taskHistory, "requestId", null)
                  )
                ),
                null
              ),
              "assignedTo",
              null
            )
          )
        ),
        touniformstring(
          index(
            index(
              ri!taskHistory,
              wherecontains(
                tointeger(fv!item.stateroomRequestId),
                tointeger(
                  index(ri!taskHistory, "requestId", null)
                )
              ),
              null
            ),
            "assignedTo",
            null
          )
        ),
        rule!APN_displayGroupOrUsername(
          if(
            isusernametaken(
              touniformstring(
                index(
                  index(
                    ri!taskHistory,
                    wherecontains(
                      tointeger(fv!item.stateroomRequestId),
                      tointeger(
                        index(ri!taskHistory, "requestId", null)
                      )
                    ),
                    null
                  ),
                  "assignedTo",
                  null
                )
              )
            ),
            touser(
              touniformstring(
                index(
                  index(
                    ri!taskHistory,
                    wherecontains(
                      tointeger(fv!item.stateroomRequestId),
                      tointeger(
                        index(ri!taskHistory, "requestId", null)
                      )
                    ),
                    null
                  ),
                  "assignedTo",
                  null
                )
              )
            ),
            if(
              a!doesGroupExist(
                tointeger(
                  touniformstring(
                    index(
                      index(
                        ri!taskHistory,
                        wherecontains(
                          tointeger(fv!item.stateroomRequestId),
                          tointeger(
                            index(ri!taskHistory, "requestId", null)
                          )
                        ),
                        null
                      ),
                      "assignedTo",
                      null
                    )
                  )
                )
              ),
              togroup(
                touniformstring(
                  index(
                    index(
                      ri!taskHistory,
                      wherecontains(
                        tointeger(fv!item.stateroomRequestId),
                        tointeger(
                          index(ri!taskHistory, "requestId", null)
                        )
                      ),
                      null
                    ),
                    "assignedTo",
                    null
                  )
                )
              ),
              null
            )
          )
        )
      ),
      /*taskStatus: fv!item.taskStatus,*/
      /*assignedTo: if(*/
        /*rule!APN_isEmpty(fv!item.assignedTo),*/
        /*fv!item.assignedTo,*/
        /*rule!APN_displayGroupOrUsername(*/
          /*if(*/
            /*isusernametaken(fv!item.assignedTo),*/
            /*touser(fv!item.assignedTo),*/
            /*if(a!doesGroupExist(tointeger(split(fv!item.assignedTo,":")[2])),*/
            /*togroup(fv!item.assignedTo),*/
            /*{}*/
            /*)*/
          /*)*/
        /*)*/
      /*),*/
      taskAuditHistoryId: fv!item.taskAuditHistoryId,
      bookedSailDates: if(
        rule!CMN_checkNullOrEmpty(fv!item.bookedSailDates),
        fv!item.bookedSailDates,
        substitute(fv!item.bookedSailDates, "-", "/")
      ),
      pendingSailDates: if(
        rule!CMN_checkNullOrEmpty(fv!item.pendingSailDates),
        fv!item.pendingSailDates,
        substitute(fv!item.pendingSailDates, "-", "/")
      )
    )
  )
  )

Getting this error in my rule expression: Expression evaluation error at function 'localvariables': LocalVariables expects final parameter to be its result value, not a definition of local variable 'local!finalResult'

Rule Expression:

a!localVariables(
/*
1 - requestId, 2 - Department, 3 - Sub Department, 4 - Requestor,
5 - Status, 6 - Ship Name, 7 - Task Status
*/
local!inputList: split(ri!input, "#$"),
local!requestId: tointeger(local!inputList[1]),
local!deptIdList: tointeger(split(local!inputList[2], "-$-")),
local!subDeptIdList: tointeger(split(local!inputList[3], "-$-")),
local!requestor: touniformstring(split(local!inputList[4], "-$-")),
local!shipId: tointeger(local!inputList[6]),
local!statusIdList: touniformstring(split(local!inputList[5], "-$-")),
local!taskStatus: toboolean(local!inputList[7]),
local!result: a!flatten(
a!forEach(
items: enumerate(5),
expression: a!localVariables(
local!batchSize: 2000,
local!startIndex: if(
tointeger(fv!index) = 1,
1,
1 + ((fv!index - 1) * local!batchSize)
),
/*rule!BUS_QE_getBUSReqViewDetails, BUS_QE_getBUSReqVWDtlsTest*/
rule!BUS_QE_getBUSReqVWDtlsTest(
fetchtotalcount: true,
selection:{"id",
"stateroomRequestId",
"deptName",
"subDeptName",
"requestedOn",
"requestedBy",
"reasonType",
"shipName",
"status",
"pendingSailDates",
"bookedSailDates"},
filters: {
a!queryFilter(
field: "stateroomRequestId",
operator: "not null"
),
a!queryFilter(
field: "stateroomRequestId",
operator: "=",
value: local!requestId,
applyWhen: not(
rule!CMN_checkNullOrEmpty(inputValue: local!requestId)
)
),
a!queryFilter(
field: "deptId",
operator: if(
or(
rule!APN_isEmpty(local!deptIdList),
length(local!deptIdList) = 1
),
"=",
"in"
),
value: if(
or(
rule!APN_isEmpty(local!deptIdList),
length(local!deptIdList) = 1
),
tointeger(local!deptIdList[1]),
tointeger(local!deptIdList)
),
applyWhen: not(
rule!CMN_checkNullOrEmpty(local!deptIdList)
)
),
a!queryFilter(
field: "subDeptId",
operator: if(
or(
rule!APN_isEmpty(local!subDeptIdList),
length(local!subDeptIdList) = 1
),
"=",
"in"
),
value: if(
or(
rule!APN_isEmpty(local!subDeptIdList),
length(local!subDeptIdList) = 1
),
tointeger(local!subDeptIdList[1]),
tointeger(local!subDeptIdList)
),
applyWhen: not(
rule!CMN_checkNullOrEmpty(local!subDeptIdList)
)
),
a!queryFilter(
field: "status",
operator: if(
or(
rule!APN_isEmpty(local!statusIdList),
length(local!statusIdList) = 1
),
"=",
"in"
),
value: if(
or(
rule!APN_isEmpty(local!statusIdList),
length(local!statusIdList) = 1
),
touniformstring(local!statusIdList[1]),
touniformstring(local!statusIdList)
),
applyWhen: not(
rule!CMN_checkNullOrEmpty(local!statusIdList)
)
),
a!queryFilter(
field: "requestedBy",
operator: if(
or(
rule!APN_isEmpty(local!requestor),
length(local!requestor) = 1
),
"=",
"in"
),
value: if(
or(
rule!APN_isEmpty(local!requestor),
length(local!requestor) = 1
),
touniformstring(local!requestor[1]),
touniformstring(local!requestor)
),
applyWhen: not(
rule!CMN_checkNullOrEmpty(local!requestor)
)
),
a!queryFilter(
field: "shipId",
operator: "=",
value: local!shipId,
applyWhen: not(
rule!CMN_checkNullOrEmpty(local!shipId)
)
),
a!queryFilter(
field: "taskStatus",
operator: if(local!taskStatus, "not null", "is null"),
applywhen: if(isnull(local!taskStatus), false, true)
)
},
paginginfo: a!pagingInfo(startIndex: local!startIndex, batchSize: local!batchSize)
).data
)
)
),
local!finalResult: a!forEach(
items: local!result,
expression: 'type!{urn:com:appian:types}BUS_RequestViewDetail'(
reportId: fv!item.reportId,
stateroomRequestId: fv!item.stateroomRequestId,
id: fv!item.id,
requestedBy: fv!item.requestedBy,
requestedOn: fv!item.requestedOn,
deptId: fv!item.deptId,
subDeptId: fv!item.subDeptId,
subDeptName: fv!item.subDeptName,
status: fv!item.status,
reasonTypeId: fv!item.reasonTypeId,
reasonType: fv!item.reasonType,
shipId: fv!item.shipId,
shipName: fv!item.shipName,
deptName: fv!item.deptName,
taskName: fv!item.taskName,
taskDisplayName: fv!item.taskDisplayName,
taskStatus: touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"taskStatus",
null
)
),
assignedTo: if(
rule!APN_isEmpty(
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
)
),
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
),
rule!APN_displayGroupOrUsername(
if(
isusernametaken(
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
)
),
touser(
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
)
),
if(
a!doesGroupExist(
tointeger(
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
)
)
),
togroup(
touniformstring(
index(
index(
ri!taskHistory,
wherecontains(
tointeger(fv!item.stateroomRequestId),
tointeger(
index(ri!taskHistory, "requestId", null)
)
),
null
),
"assignedTo",
null
)
)
),
null
)
)
)
),
/*taskStatus: fv!item.taskStatus,*/
/*assignedTo: if(*/
/*rule!APN_isEmpty(fv!item.assignedTo),*/
/*fv!item.assignedTo,*/
/*rule!APN_displayGroupOrUsername(*/
/*if(*/
/*isusernametaken(fv!item.assignedTo),*/
/*touser(fv!item.assignedTo),*/
/*if(a!doesGroupExist(tointeger(split(fv!item.assignedTo,":")[2])),*/
/*togroup(fv!item.assignedTo),*/
/*{}*/
/*)*/
/*)*/
/*)*/
/*),*/
taskAuditHistoryId: fv!item.taskAuditHistoryId,
bookedSailDates: if(
rule!CMN_checkNullOrEmpty(fv!item.bookedSailDates),
fv!item.bookedSailDates,
substitute(fv!item.bookedSailDates, "-", "/")
),
pendingSailDates: if(
rule!CMN_checkNullOrEmpty(fv!item.pendingSailDates),
fv!item.pendingSailDates,
substitute(fv!item.pendingSailDates, "-", "/")
)
)
)

)

  Discussion posts and replies are publicly visible