List of Variables Returns Empty

I have a process model where it inserts into the database for each record. One of the rows I try to insert returns a "List of Variant" with 0 items. Now on insertion, the process model skips that row and goes to the next one and adding it to the wrong row to the current user row. Also some of the dictionaries have a property that changes the values from "short" to "long". I used the property() function to make it where if the first is missing (short), then the other returns (long). But instead of returning the other one, it returns null and inserts into the DB as null. When I use the flatten() function on the results, the "List of Variants" get skipped as well and then instead of the 100 rows it shows, I get 94 (six are like the last code example)

Here is a partial string of the response:

{
    user : {
        assignment: [
            {
                primary:true,
                homeUnit: [
                    {
                        nameCode: { codeValue: "1", shortName: "analyst"},
                        typeCode: { codeValue: "role", shortName: "role"}
                    },
                    {
                        nameCode: { codeValue: "m01", shortName: "math"},
                        typeCode: { codeValue: "dept", shortName: "dept"}
                    }
                ]
            },
            {
            primary: false,
            ...
            }
        ]
    },
    user : {
        assignment: [
            {
                primary:true,
                homeUnit: [
                    {
                        nameCode: { codeValue: "2", shortName: "engineer"},
                        typeCode: { codeValue: "role", shortName: "role"}
                    },
                    {
                        nameCode: { codeValue: "s101", shortName: "science"},
                        typeCode: { codeValue: "dept", longName: "dept"} /* notice longName instead of shortName */
                    }
                ]
            }
        ]
    },
    user : {
        assignment:[ {primary:true}, {primary:false}] /* causing List of Variant - 0 items */
    }
}

Here is the response handler:

index(
a!forEach(
    items: local!response.body.user.assignment.homeUnit
      , expression: if(
        wherecontains("role",touniformstring(fv!item.typeCode.shortName))
        ,property(fv!item.nameCode,"shortName",fv!item.nameCode.longName),"") /*doesn't work*/
    )
    ,where(local!response.body.user.assignment.isPrimary),"")
    
    )

As mentioned before, this is the what returns a List of Variants with 0 items:

assignment : [
    {primary: true},{primary:false}
]

Is this by design with the function to make it skip if it's a List of Variant type? Or how may I convert the List of Variant to an empty string in order to insert a blank value into the DB? Also why doesn't the property() function catch the other alternative property name (valueIfMissing)? 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I think you're making a series of potentially false assumptions about how this looping will work over the data you're passing in.

    It seems from your top code block like you're getting

    • an array of "user"
      • each of which will have an array of "assignment"
        • each having an array of "home unit"

    So I'm not sure what you're expecting when you call a!forEach() over "local!response.body.user.assignment.homeUnit", but it seems to me like it will maybe only be looping over one of those bottom-level collections.  In that case of course, for the first instance there is no "longName" (per what I can currently see there), because the "longName" property doesn't exist until the second instance of user.  Or are you expecting all instances of these to be flattened before being parsed by a!forEach()?  Again I'm a little unclear what you're expecting and what you're hoping the output to be, but I think you might need to get a better handle on what your input data set is exactly, and how to parse through it using Appian's functionality.

Reply
  • 0
    Certified Lead Developer

    I think you're making a series of potentially false assumptions about how this looping will work over the data you're passing in.

    It seems from your top code block like you're getting

    • an array of "user"
      • each of which will have an array of "assignment"
        • each having an array of "home unit"

    So I'm not sure what you're expecting when you call a!forEach() over "local!response.body.user.assignment.homeUnit", but it seems to me like it will maybe only be looping over one of those bottom-level collections.  In that case of course, for the first instance there is no "longName" (per what I can currently see there), because the "longName" property doesn't exist until the second instance of user.  Or are you expecting all instances of these to be flattened before being parsed by a!forEach()?  Again I'm a little unclear what you're expecting and what you're hoping the output to be, but I think you might need to get a better handle on what your input data set is exactly, and how to parse through it using Appian's functionality.

Children
No Data