Merge muliple columns from resultset dynamically

I have a datasubset DS containing properties X, Y and others. I am trying to take the property X and Y dynamically and do the merge ( property names are passed dynamically ).

Below script didnt work because apply is returning a single array with all the values for X and Y. Is there any other way to do it?

local!propertyName_txts: {
    "X",
    "Y"
  },
  merge(
    apply(
      fn!property(
        local!DS_ds.data,
        _
      ),
      local!propertyName_txts
    )
  )

 

  Discussion posts and replies are publicly visible

Parents
  • Hello Bbalasubramanik,

    which version of Appian are you using?

    I don't fully understand what you want to achieve. But I did the test and I got the following:

     

    with(
    local!data :{{X:"x1", Y:"Y1", Z:"Z1"},
    {X:"x2", Y:"Y2", Z:"Z2"},
    {X:"x3", Y:"Y3", Z:"Z3"},
    {X:"x4", Y:"Y4", Z:"Z4"},
    {X:"x5", Y:"Y5", Z:"Z5"}} ,
    local!DS_ds:a!dataSubset(startIndex:1,batchSize:100, totalCount:5, data:local!data, identifiers:local!data.X),
    local!propertyName_txts: {
        "X",
        "Y"
      },
      merge(
        apply(
          fn!property(
            local!DS_ds.data,
            _
          ),
          local!propertyName_txts
        )
      )
    
     )

     

    This is what I Got 

    Test OutputHide section contents
    
    Time	
    2 ms
    Type	
    List of Variant
    Value	
    List of Variant: 2 items
        List of Variant: 5 items
            "x1"
            "x2"
            "x3"
            "x4"
            "x5"
        List of Variant: 5 items
            "Y1"
            "Y2"
            "Y3"
            "Y4"
            "Y5"

    What are you expecting to get? 

    This is what I got
    {
    {"x1", "x2", "x3", "x4", "x5"},
    {"Y1", "Y2", "Y3", "Y4", "Y5"}
    }

     

    do you want to obtain something like this?

    {{"x1","Y1"},
    {"x2","Y2"},
    {"x3","Y3"},
    {"x4","Y4"},
    {"x5","Y5"}}

    If you are using V17.2 maybe this will help

    with(
      local!data: {
        {X: "x1",Y: "Y1",Z: "Z1"},
        {X: "x2",Y: "Y2",Z: "Z2"},
        {X: "x3",Y: "Y3",Z: "Z3"},
        {X: "x4",Y: "Y4",Z: "Z4"},
        {X: "x5",Y: "Y5",Z: "Z5"}
      },
      local!DS_ds: a!dataSubset(
        startIndex: 1,
        batchSize: 100,
        totalCount: 5,
        data: local!data,
        identifiers: local!data.X
      ),
      local!propertyName_txts: {
        "X",
        "Y"
      },
      a!forEach(
        items: local!DS_ds.data,
        expression: {
          with(
            local!tempData: fv!item,
            a!forEach(
              items: local!propertyName_txts,
              expression: with(
                local!propertyName: fv!item,
                property(
                  local!tempData,
                  local!propertyName
                )
              )
            )
          )
        }
      )
    )

     

    Jose Perez

  • Thanks for your response. I needed below output and I am using 16.2 version.

    {{"x1","Y1"},
    {"x2","Y2"},
    {"x3","Y3"},
    {"x4","Y4"},
    {"x5","Y5"}}
  • Create a new rule : 

    /*
      Rule Name : FormatDetail
      Input1 : TEXT
      Input2 : TEXT
    */
    
    =with(
      {
        ri!Input1,
        ri!Input2
      }
    )

     

     

    /* Calling rule */
    
    apply(
      rule!FormatDetail(
        _,
        _
     ),
        merge(
         property( local!DS_ds.data,"X",{}),
         property( local!DS_ds.data,"Y",{})
        )
    )

Reply Children
  • Hi Vinay, I will be passing the properties X and Y dynamically, it could be X and Z (or) X and Y based on scenarios. I need to do the merge of these dynamically passed properties in the datasubset.
  • Ok please find the below code, hope this will work

     

    with(
      local!data: {
        {X: "x1",Y: "Y1",Z: "Z1"},
        {X: "x2",Y: "Y2",Z: "Z2"},
        {X: "x3",Y: "Y3",Z: "Z3"},
        {X: "x4",Y: "Y4",Z: "Z4"},
        {X: "x5",Y: "Y5",Z: "Z5"}
      },
      local!DS_ds: a!dataSubset(
        startIndex: 1,
        batchSize: 100,
        totalCount: 5,
        data: local!data,
        identifiers: local!data.X
      ),
      local!propertyName_txts: {
        "X",
        "Z"
      },
     
      
    local!DynamicData:
          apply(
           index( local!DS_ds.data,_,{}),
           local!propertyName_txts
          ),
          
    apply(
      rule!FormatDetail(
        Index:_,
        Array:local!DynamicData
      ),
      1 + enumerate(local!DS_ds.totalCount)
    )      
     
     
    )
      
    

     

    New Rule

    FormatDetail

    /*
    Inputs
      Index : Number
      Array : AnyType
    */
    
    =with(
      {
        ri!Array[1][ri!Index],
        ri!Array[2][ri!Index] 
      }
      
    )