Hi, 1)For below records or dataset, how can I replace "col4"

Hi,

1)For below records or dataset, how can I replace "col4" with a set of columns ("col41", "col42", "col43") dynamically in the records?
Input:
{
{col1: "dcgsdf", col2: "thstr", col3: 1, col4: "jtsjre", col5:56},
{col1: "asdg", col2: "jtrj", col3: 53, col4: "srtjgsf", col5:32},
{col1: "fdhd", col2: "dfhs", col3: 21, col4: "srtjf", col5:3},
{col1: "rae", col2: "DGAS", col3: 45, col4: "sjfgj", col5:0}
}

Output:

{
{col1: "dcgsdf", col2: "thstr", col3: 1, col41: "re", col42: "ad", col43: "sasd", col5:56},
{col1: "asdg", col2: "jtrj", col3: 53, col41: "sjgsf", col42: "erw", col43: "sadf", col5:32},
{col1: "fdhd", col2: "dfhs", col3: 21, col41: "tjf", col42: "asd", col43: "afsd", col5:3},
{col1: "rae", col2: "DGAS",col3: 45, col41: "fgj", col42: "sf", col43: "wewf", col5:0}
}

OriginalPostID-207581

OriginalPostID-207581

  Discussion posts and replies are publicly visible

  • Not sure this question makes much sense. In that example (the one I gave you), the col2, col4, names are representing the field names in a dictionary item. However, normally it would be a CDT, and "replacing" the fields names of a CDT dynamically isn't something you'd normally do. What exactly are you trying to accomplish?
  • Hi Philb, Basically these columns are coming from DB using Data Store. As per requirement I am supposed to break the column (col4) into no of columns dynamically. The final grid will contain the information as per given output data.
  • So you're splitting a single attribute into an array? Does the single element always produce the same number of items or is it variable? What does the data look like - is it delimited? Why is the data not split by the database? A more accurate example would help to show exactly what is required.
  • Yes, you are right. We have to split the attribute by a delimiter "~". The final grid will have a variable no of columns.
  • In continuation to my previous reply....... I am trying to implement a grid which can dynamically create columns based on the data of a single column returned by DB. To explain more preciously, I am getting below table data for Code=xyz. The given dataset contains the complete data I need to show in the grid, however the 'Detailed' column has the set of columns and it's value which I need to split and show in my final grid along with other columns.

    Code          col2           col3           Detailed                                        col6
    xyz                    asdfsa          ad                    col4~asd|col5~uwu                    adf
    xyz                    er                    we                    col4~ut|col5~uu           cwe
    xyz                    qqw                    rr                    col4~co|col5~uw                    asdfw

    The Detailed column contains the columns separated by '|' and every column name and it's value is separated by '~'. Other than this I also have the details of columns set (name) for given Code=xyz, which is suppose to be different for different Codes (in this case it is "col4", and "col5" for Code=xyz).

    Once I retrieve all the columns from 'Detailed' column, appian should show the grid with following details.

    Code          col2           col3           col4           col5           col6
    xyz                    asdfsa          ad                    asd                    uwu                    adf
    xyz                    er                    we                    ut                    uu                    cwe
    xyz                    qqw                    rr                    co                    uw                    asdfw

    I am trying to implement this with the help of gridTextColumn and gidField, however I find it difficult to prepare the data in the format which gridField expects for this.

    Thanks for the help!
  • I'm assuming you can't change how the data is stored for that fourth column? Because it's kind of horrible :)

    Are the columns within the data for that fourth column a fixed number of columns, or are they dynamic?
  • Hi Philb, Yes you are right, we can't change the data stored in the fourth columns :) And the columns within the data for the fourth column is variable. As I said, I make another DB call to get the list of columns I need to show for particular Code.
  • I think what you need to do is fix the columns that don't change - col1, 2, 3 and 5 in your example - by "hardcoding" the columnconfigs - and then insert() the result of a couple of nested applys - the first apply would loop over the col4 data which has been split using the | symbol and return a column, then for each iteration of that apply you'll need another that loops over each element of that split data, splitting it again using the ~ symbol to get the values that need to be displayed.
  • Attached is an application that contains a working example - have a look and see what you think.

    PB_207581.zip

  • Whoops, forgot to include the folder for the rules - new export attached.

    PB_207581.zip