a!gridrowlayout in a!foreach

Certified Senior Developer

I am trying to loop the multiple gridrowlayout of a editiable grid  using a!foreach but not able to do it.

can i have some directions with possible code.

I required to flash multiple rows with loop on count of queries declared in the interface by the user

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Please refer the below code.

    a!localVariables(
      local!count,
      local!tech,
      local!gridData: if(
        a!isNullOrEmpty(local!count),
        null,
        a!forEach(
          items: enumerate(local!count) + 1,
          expression: { ques: "", option: "" }
        )
      ),
      {
        a!textField(
          label: "Tech",
          value: local!tech,
          saveInto: local!tech
        ),
        a!textField(
          label: "Count",
          value: local!count,
          saveInto: local!count
        ),
        a!gridLayout(
          headerCells: {
            a!gridLayoutHeaderCell(label: "Question"),
            a!gridLayoutHeaderCell(label: "Options")
          },
          rows: a!forEach(
            items: local!gridData,
            expression: a!gridRowLayout(
              contents: {
                a!textField(
                  value: fv!item.ques,
                  saveInto: fv!item.ques
                ),
                a!textField(
                  value: fv!item.option,
                  saveInto: fv!item.option
                )
              }
            )
          )
        )
      }
    )

  • 0
    Certified Senior Developer
    in reply to Deepak gupta

    Thanks for this support...

    but now how can we use fv!index on this for each iteration..

  • 0
    Certified Senior Developer
    in reply to om786

    Where you want to use fv!index and why?

  • 0
    Certified Senior Developer
    in reply to Deepak gupta

    Actually i want to enter multiple row enteries on a single shot of submit button. so in order to input the data in the DB, we have to run the different  rows in the interface with the help of separate index no. so that it will help to create a unique identifier for each record in the DB. 

    Here i am using Questions & Answers table in Array CDT. 

  • 0
    Certified Senior Developer
    in reply to om786

    is you primary key column in Auto generated? If yes, then it is not required to assign any value to primary key column. If not, then on the click on submit button,into save into you can use writetoDatastoreentity function and in that you can use foreach loop.

  • I pretty much always use the submit button to handle any complex logic that you need before the form is submitted. As long as you can construct some kind of rule that adds the appropriate indexes you need, just add an a!save() on your submit button to then execute that rule and save it's results.

    If you are looking for more specific guidance on handling indexing / manipulating data, I think we need a lot more information about what you are trying to do (preferably with an example or sample code).

  • 0
    Certified Senior Developer
    in reply to Peter Lewis

    Pls find the interface screenshot with code.

    a!localVariables(
    local!tech,
    local!count: null,
    local!counts: repeat(local!count, " "),
    a!formLayout(
    label: "Questionare",
    contents: {
    a!columnsLayout(
    columns: {
    a!columnLayout(
    contents: {
    a!dropdownField(
    label: "Technology",
    labelPosition: "JUSTIFIED",
    placeholder: "--- Select a Value ---",
    choiceLabels: rule!MCS_GetTechnologyName().subname,
    choiceValues: rule!MCS_GetTechnologyName().subid,
    value: local!tech,
    saveInto: {
    a!save(local!tech, save!value),
    a!save(ri!Queries.subid, local!tech)
    },
    searchDisplay: "AUTO",
    validations: {}
    )
    }
    ),
    a!columnLayout(
    contents: {
    a!dropdownField(
    label: "Count of Queries",
    labelPosition: "JUSTIFIED",
    placeholder: "--- Select a Value ---",
    choiceLabels: cons!MCS_COUNTOFQUESTIONS,
    choiceValues: cons!MCS_COUNTOFQUESTIONS,
    value: local!count,
    saveInto: local!count,
    searchDisplay: "AUTO",
    required: true,
    validations: {}
    )
    }
    ),
    a!columnLayout(contents: {})
    }
    ),
    a!gridLayout(
    label: "Enter Questionnaire ",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Question"),
    a!gridLayoutHeaderCell(label: "Option Available"),
    a!gridLayoutHeaderCell(label: "Correct Option")
    },
    columnConfigs: {},
    rows: {
    a!forEach(
    items: local!counts,
    expression: a!gridRowLayout(
    contents: {
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    saveInto: {},
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    saveInto: {},
    refreshAfter: "UNFOCUS",
    validations: {}
    ),
    a!textField(
    label: "Text",
    labelPosition: "ABOVE",
    saveInto: {},
    refreshAfter: "UNFOCUS",
    validations: {}
    )
    }
    )
    )
    },
    selectionSaveInto: {},
    validations: {},
    shadeAlternateRows: true
    )/*a!textField(*/
    /*label: "Text",*/
    /*labelPosition: "ABOVE",*/
    /*saveInto: {},*/
    /*refreshAfter: "UNFOCUS",*/
    /*validations: {}*/
    /*)*/

    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit",
    submit: true,
    style: "PRIMARY",
    loadingIndicator: true
    )
    },
    secondaryButtons: {
    a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: {},
    submit: true,
    style: "NORMAL",
    validate: false
    )
    }
    )
    )
    )

  • 0
    Appian Employee
    in reply to om786

    Ok a few suggestions:

    • In your local!counts variable at the top, you should define that variable as a complex type and not just as a list of strings. Do you have a CDT or Record that you could use for that variable that has information for your question / option / correct options? Even if you don't, I'd suggest using a map, which would allow you to save any data you need to. Here's how you could construct it with a map:

      local!counts: repeat(local!count, a!map()),

    • You also don't have anything that's actually saving in your text fields. You should include code like this to actually save the data:

      saveInto: fv!item.question,
      value: fv!item.question,