How to convert CDT list into List of Varient

I have a List of Data of type CDT, i wanted to convert that into List of varient to use that data in A!forEach() ??? 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Considering that a!forEach() can act on any list type (including list of CDT), i'm not sure why you would want to do this - can you explain a bit more about your use case?

  • 1.      In my process model I have a process variable of type 

    type!MB_Medicine__Cost_Data_fromExcel (urn:com:appian:types:mb) id, name, perCost, quantity, totalCost

    id (Number (Integer))

    name (Text)

    perCost (Number (Integer))

    quantity (Number (Integer))

    totalCost (Number (Integer))

    2.     Inside this I already have data stored. Assume a list of 5.

            Now what I need to do is I need to find the name: "Cipla" and wanted to change its perCost. 

           So, I have created a rule expression and passed my variable into that rule using rule input.

    3.     a!localVariables(
            local!dataInput:ri!oldData,
            local!finalUpdate:a!forEach(
            items: local!dataInput,
            expression: a!localVariables(
            local!checking:"cipla",
           'type!{urn:com:appian:types:mb}MB_Medicine__Cost_Data_fromExcel'(
           name: if(fv!item[1]=local!checking,"ciplex",fv!item[1]),
           perCost: fv!item[2],
           quantity: fv!item[3],
           totalCost: fv!item[4],
         )
         )
         ),
         local!finalUpdate
        )

    4. In my rule Exp . ri!oldData contains the data of type!MB_Medicine__Cost_Data_fromExcel

    5. So , it is not parsing in foreach and gives error

    6. I also used tojson() and fromjson() but it is also converting into dictionary

    I need to convert ri!OldData into List of varient so i can parse it and change the data of cipla only ??

  • you can also suggest some other ways or shortcut to make it done

  • 0
    Certified Lead Developer
    in reply to akshays0003

    my initial feedback is that you're misusing "fv!item[1]" (etc).  Each "fv!item" will be a single instance of your CDT but your square-bracket index calls make Appian want to treat "fv!item" like an array -- which it isn't.  So you'll need to fix that before this expression will work, regardless of the data type.

  • How can we parse 2-D array then? . In my case the variable contains:

    [id=, name=pfizer, perCost=100, quantity=2, totalCost=200],[id=, name=cipla, perCost=120, quantity=2, totalCost=240],[id=, name=beta, perCost=90, quantity=1, totalCost=90],[id=, name=pathlabs, perCost=88, quantity=4, totalCost=352],[id=, name=nlabs, perCost=30, quantity=3, totalCost=90],[id=, name=cx100, perCost=230, quantity=2, totalCost=460],[id=, name=, perCost=, quantity=, totalCost=1432]

    ----------------------------------------------------------------------------------------------------------

    I have load this data from excel with method below and it is working fine:

          a!localVariables(
             local!excelFile:readexcelsheet(
             excelDocument:ri!docId,
             sheetNumber:0,
             startRow:5
          ).result,
          local!excelinArray:a!flatten(local!excelFile),
          local!finalOut:a!forEach(
             items: local!excelinArray.values,
             expression:'type!{urn:com:appian:types:mb}MB_Medicine__Cost_Data_fromExcel'(
             name: fv!item[1],
             perCost: fv!item[2],
             quantity: fv!item[3],
             totalCost: fv!item[4]
          )
         ),
         local!finalOut

    )

    -------------------------------------------------

    the problem comes after this when i want to change some values

Reply
  • How can we parse 2-D array then? . In my case the variable contains:

    [id=, name=pfizer, perCost=100, quantity=2, totalCost=200],[id=, name=cipla, perCost=120, quantity=2, totalCost=240],[id=, name=beta, perCost=90, quantity=1, totalCost=90],[id=, name=pathlabs, perCost=88, quantity=4, totalCost=352],[id=, name=nlabs, perCost=30, quantity=3, totalCost=90],[id=, name=cx100, perCost=230, quantity=2, totalCost=460],[id=, name=, perCost=, quantity=, totalCost=1432]

    ----------------------------------------------------------------------------------------------------------

    I have load this data from excel with method below and it is working fine:

          a!localVariables(
             local!excelFile:readexcelsheet(
             excelDocument:ri!docId,
             sheetNumber:0,
             startRow:5
          ).result,
          local!excelinArray:a!flatten(local!excelFile),
          local!finalOut:a!forEach(
             items: local!excelinArray.values,
             expression:'type!{urn:com:appian:types:mb}MB_Medicine__Cost_Data_fromExcel'(
             name: fv!item[1],
             perCost: fv!item[2],
             quantity: fv!item[3],
             totalCost: fv!item[4]
          )
         ),
         local!finalOut

    )

    -------------------------------------------------

    the problem comes after this when i want to change some values

Children