foreach incrementation

{a!localVariables(
local!item:0,
a!forEach(
items: enumerate(2),
expression: a!columnsLayout(
columns: a!localVariables(
local!outerIndex: fv!item,
local!item:1,
a!forEach(
items: 1+enumerate(3),
expression: a!columnLayout(
contents: a!cardLayout(
style: "INFO",
contents: {
a!textField(
value:local!item,
saveInto:a!save(local!item,tointeger(local!item)+1),
),
a!richTextDisplayField(
labelPosition: "COLLAPSED",
align: "CENTER",
value: a!richTextItem(
text:local!item,
color: "#1a1a00",
size: "MEDIUM",
),
),
},
height: "MEDIUM",
shape: "ROUNDED",
),

)
)
)
)
),
)
}

The above code will have 2 columns and 3 rows.

it is giving the below output.

but i want to display 1 2 3

                                  4 5 6.

If i apply some logic , i will get 1 2 3

                                                 3 4 5

incrementing variable also not possible here. kindly help.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Please use a Code Box, which preserves indentation/formatting and improves readability of code (back up out of the negatives)...

  • 0
    Certified Lead Developer

    I'm not really clear what you're trying to do here overall, but you seem to be misunderstanding how local variables work and how saveInto works.  For instance, the local!item: 0 you declare on line 2 is irrelevant to this code snippet as it's never used, since you supersede it in scope by re-declaring local!item inside your forEach loop, on line 8. 

    Additionally, local!outerIndex is never used either.  And the saveInto you're doing in your text field (whether this is your intended behavior or not, i honestly can't tell), just adds 1 to the current grid row's local!item value, regardless of what the user inputs (and has no effect whatsoever prior to the user interacting with the text field).

  • if the number of row increases , the one which was discussed earlier was not working.

  • i have 2 columns and number of rows depends on dynamic data.

    if i have 20 values means first 10 value in column1 and next 10 value in column2.

    e.g

    outerforeach:enumerate(2)

    innerforeach:enumerate(20)

    i have used   (fv!index+(local!outerIndex-1)*2) ----this logic to print the number from 1 to 20 in the given column layout as suggested earlier in this forum..

    but it is printing 1 to 10 in 1st column layout, and 3 to 12 in another column layout.

    it is not in sequence. unable to increment the fv!index as well.

  •  a!localVariables(
       local!selectedColumn:0,
       local!createdcard:0,   
       local!datas: {
         {Name:"Name1",Description:"Description1"},
         {Name:"Name2",Description:"Description2"},
         {Name:"Name3",Description:"Description3"},                          
         {Name:"Name4",Description:"Description4"},                          
         {piName:"Name5",Description:"Description5"},
         {Name:"Name6",Description:"Description6"},
         {Name:"Name7",Description:"Description7"},
         {Name:"Name8",Description:"Description8"},                          
         {Name:"Name9",Description:"Description9"},                          
         {Name:"Name10",Description:"Description10"},  
         {Name:"Name11",Description:"Description11"},
         {Name:"Name12",Description:"Description12"},
         {Name:"Name13",Description:"Description13"},                          
         {Name:"Name14",Description:"Description14"},                          
         {Name:"Name15",Description:"Description15"},  
       },
     local!selectedCard,
     {
       a!richTextDisplayField(
    
         labelPosition: "COLLAPSED",
         value: {
           char(10),         
           a!richTextItem(
             text: "Datas",
             color: "#b366ff",
             size: "LARGE"
           ),
           char(10)
         },
    
         showWhen: isNull(local!selectedCard),
         align: "CENTER"
       ),  
     
     {
       a!columnsLayout(
         marginBelow: "NONE",
         spacing: "NONE",
         columns: {
           a!columnLayout(),
           a!forEach(
             items: 1+enumerate(2),                        
             expression: {
               a!localVariables(
                 local!outerIndex:fv!index,
                 a!columnLayout(
                   contents: {
                     a!forEach(
                       items:1+enumerate(count(local!datas.Name)),
                       expression: {
                         a!localVariables(
                           local!innerIndex:fv!index,
                           a!cardLayout(
                             style: "INFO",                             
                             contents: {                                    
                               a!richTextDisplayField(
                                 labelPosition: "COLLAPSED",
                                 value: {
                                   char(10),
                                   char(10),
                                   a!richTextItem(
                                     text:if(((fv!index+(local!outerIndex-1)*2)>count(local!datas.Name))," ",local!datas[fv!index+(local!outerIndex-1)*2].Name),
                                     color: "#1a1a00",
                                     size: "MEDIUM"
                                   ),
                                   char(10),
                                   char(10),
                                   a!richTextItem(
                                     text: if(((fv!index+(local!outerIndex-1)*2)>count(local!datas.Name))," ",local!datas[fv!index+(local!outerIndex-1)*2].Description),
                                     color: "#1a1a00",
                                     size: "SMALL",
                                     style: "PLAIN"
                                   ),
                                   char(10),
                                   
                                   a!richTextItem(
                                     text: " ",
                                     color: "#1a1a00",
                                     size: "SMALL",
                                     style: "PLAIN"
                                   )
    
                                 },
                                 align: "LEFT"
    
                               ),
                               a!richTextDisplayField(
                                 labelPosition: "COLLAPSED",                      
                                 value: a!richTextItem(                        
                                   text: {
                                     a!richTextIcon(
                                       icon: "external-link",
                                       altText: "external-link"
    
                                     ),
                                     " ",
                                     "viewmore" &" "&(fv!index+(local!outerIndex-1)*2),
    
                                   },
    
                                   link: a!dynamicLink(
                                     saveInto: {
                                       a!save(local!selectedCard, if(((fv!index+(local!outerIndex-1)*2)>count(local!datas.Name))," ",local!datas[fv!index+(local!outerIndex-1)*2].Name)),
                                       a!save(local!selectedColumn,1),
                                       a!save(local!createdcard,(fv!index+(local!outerIndex-1)*2)),
                                       
    
                                     }
                                   ),
                                   linkStyle: "STANDALONE",
                                   color:"#a64dff"
                                 ),
                                 align: "CENTER",
                               ) 
                             },
                             height: "MEDIUM",
                             shape:"ROUNDED",
                             showWhen: tointeger((fv!index+(local!outerIndex-1)*2))<=count(local!datas.Name),
                           )
                           
    
                         ) ,
                         a!cardLayout(showBorder: false), 
                         
                       },
    
                     ) 
                   },                          
    
                   width: "MEDIUM_PLUS"
                 )
               ),a!columnLayout()
             }
            
           ),
          
         },                  
         /*showWhen: isNull(local!selectedCard),                  */
         showWhen: tointeger(local!selectedColumn=0)
    
       ),
     }
     }
     
     )

    This is code i have tried

  • Can you please try below code

    a!localVariables(
    local!item:0,
    a!forEach(
    items: enumerate(2),
    expression: a!columnsLayout(
    columns: a!localVariables(
    local!outerIndex: fv!item,
    local!item:fv!index,
    a!forEach(
    items: enumerate(3),
    expression: a!columnLayout(
    contents: a!cardLayout(
    style: "INFO",
    contents: {
    a!textField(

    value: (((local!item + fv!index) - 1) + ((local!item - 1) * 2) )


    ),
    a!richTextDisplayField(
    labelPosition: "COLLAPSED",
    align: "CENTER",
    value: a!richTextItem(
    text:local!item,
    color: "#1a1a00",
    size: "MEDIUM",
    ),
    ),
    },
    height: "MEDIUM",
    shape: "ROUNDED",
    ),

    )
    )
    )
    )
    ),
    )

  • for enumerate(3),getting the below output

    if i increase the enumeration to 10 .i.e enumerate(10),getting the below output

  • Hi Nandhinip,

    I hope this will sort your problem. Hope you will get desired results now.

    a!localVariables(
    local!item:0,
    local!outerEnum: 3,
    local!innerEnum: 8,
    a!forEach(
    items: enumerate( local!outerEnum),
    expression: a!columnsLayout(
    columns: a!localVariables(
    local!outerIndex: fv!item,
    local!item:fv!item,
    a!forEach(
    items: enumerate(local!innerEnum),
    expression: a!columnLayout(
    contents: a!cardLayout(
    style: "INFO",
    contents: {
    a!textField(

    value: ((local!innerEnum * local!item) + fv!index),


    ),
    a!richTextDisplayField(
    labelPosition: "COLLAPSED",
    align: "CENTER",
    value: a!richTextItem(
    text:local!item,
    color: "#1a1a00",
    size: "MEDIUM",
    ),
    ),
    },
    height: "MEDIUM",
    shape: "ROUNDED",
    ),

    )
    )
    )
    )
    ),
    )

  • 0
    Certified Lead Developer
    in reply to rahata9316

    Which purpose has the local!item in line 2? And why do you store fv!item inside the outer loop into two different locals?

    Regarding variables in Appian Interfaces I recommend my blog article: appian.rocks/.../

    Next time, please use this function: