unable to use if else in Expression rule

a!localVariables(
  
  local!reassigndetail: a!queryEntity(
    entity: cons!MPPCONSDSE_MPPTABSAM_task,
    query: a!query(
      selection: a!querySelection(
        columns: {
          a!queryColumn(
            field: "ReassignEmail"
          ),
          a!queryColumn(
            field: "samaccid"
          )
        }
      ),
      logicalExpression: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: "Reassign",
            operator: "=",
            value: "Yes"
          ),
          a!queryFilter(
            field: "annoucncementid",
            operator: "=",
            value: ri!Announcementid
          )
        },
        ignoreFiltersWithEmptyValues: true
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: -1
      )
    ),
    fetchTotalCount: false
  ).data,

  
  local!fabdetails:
  a!forEach(
    items:local!reassigndetail,
    expression:rule!MPPER_getFabsnamefromsamaccid(fv!item.samaccid)

  ),
  local!fabdetails2: a!forEach(a!flatten( local!fabdetails).fabname,fv!item),
  local!samemails: a!forEach(a!flatten( local!reassigndetail).ReassignEmail,fv!item)
  ,

  
  local!samdata : a!queryEntity(
    entity: cons!MPPCONSCDT_SAMAccountability,
    query: a!query(
      logicalExpression: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: "samemail",
            operator: "in",
            value:local!samemails
          ),
          a!queryFilter(
            field: "fabname",
            operator: "in",
            value:local!fabdetails2
          )
        },
        ignoreFiltersWithEmptyValues: true
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 50
      )
    ),
    fetchTotalCount: false
  ).data,
  
  local!result:
  a!forEach(
    items:local!samdata,
    expression: cast(typeof('type!{urn:com:appian:types}MPPSAMAccoumtability'()),fv!item)
  ),
  local!result

  
  
)

this works fine if local!reassigndetail finds some data from DB using a!queryentity but when it doesn't return any data from db then it gives following error

Expression evaluation error at function a!forEach [line 47]: Invalid index: Cannot index property ’’fabname’’ of type String into type List of Variant

Please help

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    When the database returns 0 rows, it takes the form of "{}", which has the type "List of Variant".  You need to return at least one row with data in it before Appian can be aware of what the fields are even supposed to be.  You don't even get the structure without returning at least a row of data.

    So, the solution is to wrap your logic inside an if function, which contains three parameters:

    The first parameter uses APN_isEmpty() or length() = 0 to determine if you returned 0 rows,

    The second parameter returns whatever you want to return in the case of 0 rows of data being returned by the query, could be as simple as "{}",

    The third parameter is what you were doing before, which only works when you have data to work on.

    Over time, you'll learn to wrap practically everything you write in "if is empty" or "if is blank".  A great many of us call it "null safety."

  • a!localVariables(
      
      local!reassigndetail: a!queryEntity(
        entity: cons!MPPCONSDSE_MPPTABSAM_task,
        query: a!query(
          selection: a!querySelection(
            columns: {
              a!queryColumn(
                field: "ReassignEmail"
              ),
              a!queryColumn(
                field: "samaccid"
              )
            }
          ),
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: "Reassign",
                operator: "=",
                value: "Yes"
              ),
              a!queryFilter(
                field: "annoucncementid",
                operator: "=",
                value: ri!Announcementid
              )
            },
            ignoreFiltersWithEmptyValues: true
          ),
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: -1
          )
        ),
        fetchTotalCount: false
      ).data,
      local!result:null,
      local!fabdetails,local!fabdetails2,local!samdata,local!samemails,
      if(length(local!reassigndetail)==0,
        local!result,
        
        {
          local!fabdetails:
          a!forEach(
            items:local!reassigndetail,
            expression:rule!MPPER_getFabsnamefromsamaccid(fv!item.samaccid)
    
          ),
          local!fabdetails2: a!forEach(a!flatten( local!fabdetails).fabname,fv!item),
          local!samemails: a!forEach(a!flatten( local!reassigndetail).ReassignEmail,fv!item)
          ,
    
    
          local!samdata : a!queryEntity(
            entity: cons!MPPCONSCDT_SAMAccountability,
            query: a!query(
              logicalExpression: a!queryLogicalExpression(
                operator: "AND",
                filters: {
                  a!queryFilter(
                    field: "samemail",
                    operator: "in",
                    value:local!samemails
                  ),
                  a!queryFilter(
                    field: "fabname",
                    operator: "in",
                    value:local!fabdetails2
                  )
                },
                ignoreFiltersWithEmptyValues: true
              ),
              pagingInfo: a!pagingInfo(
                startIndex: 1,
                batchSize: 50
              )
            ),
            fetchTotalCount: false
          ).data,
    
          local!result:
          a!forEach(
            items:local!samdata,
            expression: cast(typeof('type!{urn:com:appian:types}MPPSAMAccoumtability'()),fv!item)
          ),
          local!result
          
          
        }
        
      
      )
     
    
      
      
    )
    

    When I use if else,

    when 0 rows are return it shows 'null', when more are returned then below error:

  • 0
    Certified Lead Developer
    in reply to arshbirs0001

    What is the purpose behind calling a!flatten here?

Reply Children
No Data