Add new row in the middle of the grid

I have enhancement requirement , I have editable grid and when user add new row to the grid it should be inserted before the last row ,  Is that possible if yes can anyone help to get started with?

Below is my existing code 

 

a!localVariables(
  local!feeDetails: ri!feeDetails,
  local!minimumFee: reject(
    fn!isnull,
    a!flatten(
      a!forEach(
        items: ri!feeDetails,
        expression: if(
          and(
            toboolean(
              fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{be1056cb-8331-4446-8fa4-3081fc64bc73}isactive']
            ) = toboolean(true()),
            tointeger(
              fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{30de7239-941c-401f-ad56-2672421eba71}scenarioId']
            ) = tointeger(
              ri!selectedScenario['recordType!{94f6f945-ec9c-4178-8b3f-684a5547bb00}PRC Scenarios.fields.{ad9e991c-6487-437f-8665-fe15a96eba42}prcScenarioId']
            ),
            tointeger(
              fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{6e4fe629-03b7-49fe-8d52-f541257e3ca5}planId']
            ) = tointeger(
              ri!selectedPlan['recordType!{3b41856e-be2b-486e-b0f7-09436ce2d07e}PRC Plan.fields.{4903a64b-b0f8-4ddb-98d1-00bcc0e648d1}prcPlanId']
            ),
            tointeger(
              fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7e014768-277f-4844-a8d0-7c6baeccf934}iteration']
            ) = tointeger(ri!iteration),
            or(
              isnull(
                fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4a8a03ee-98f5-4712-8135-4c235968e033}serviceExId']
              ),
              contains(
                { 27, 75, 261, 251, 271 },
                fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4a8a03ee-98f5-4712-8135-4c235968e033}serviceExId']
              )
            )
          ),
          fv!item,
          null
        )
      )
    )
  ),
  local!minimumIndex: index(local!minimumFee, 1, {}),
  local!minimumValue: if(
    isnull(local!minimumIndex),
    tointeger(0),
    tointeger(
      index(
        local!minimumIndex,
        'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{67613804-ab49-4df7-91d4-358b515efd47}minimumfee',
        {}
      ),
      
    )
  ),
  {
    a!cardLayout(
      marginAbove: "EVEN_MORE",
      showBorder: false,
      showShadow: true,
      contents: {
        a!sectionLayout(
          contents: a!gridLayout(
            headerCells: {
              a!gridLayoutHeaderCell("Annual Fee"),
              a!gridLayoutHeaderCell("Sequence"),
              a!gridLayoutHeaderCell("Amount"),
              a!gridLayoutHeaderCell(" "),
              
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "NARROW_PLUS"),
              a!gridLayoutColumnConfig(width: "NARROW_PLUS"),
              a!gridLayoutColumnConfig(width: "NARROW_PLUS"),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            rows: a!forEach(
              items: local!feeDetails,
              expression: if(
                and(
                  fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{be1056cb-8331-4446-8fa4-3081fc64bc73}isactive'] = true(),
                  tointeger(
                    fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{30de7239-941c-401f-ad56-2672421eba71}scenarioId']
                  ) = tointeger(
                    ri!selectedScenario['recordType!{94f6f945-ec9c-4178-8b3f-684a5547bb00}PRC Scenarios.fields.{ad9e991c-6487-437f-8665-fe15a96eba42}prcScenarioId']
                  ),
                  tointeger(
                    fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{6e4fe629-03b7-49fe-8d52-f541257e3ca5}planId']
                  ) = tointeger(
                    ri!selectedPlan['recordType!{3b41856e-be2b-486e-b0f7-09436ce2d07e}PRC Plan.fields.{4903a64b-b0f8-4ddb-98d1-00bcc0e648d1}prcPlanId']
                  ),
                  tointeger(
                    fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7e014768-277f-4844-a8d0-7c6baeccf934}iteration']
                  ) = tointeger(ri!iteration),
                  or(
                    contains(
                      { 271, 251, 261, 75, 27 },
                      fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4a8a03ee-98f5-4712-8135-4c235968e033}serviceExId']
                    ),
                    isnull(
                      fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4a8a03ee-98f5-4712-8135-4c235968e033}serviceExId']
                    )
                  )
                ),
                a!gridRowLayout(
                  id: fv!index,
                  contents: {
                    a!textField(
                      readOnly: not(ri!isEdit),
                      value: if(
                        a!isNotNullOrEmpty(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{796cea1b-ff7a-4223-a860-65e23373eab4}annualfee']
                        ),
                        concat(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{796cea1b-ff7a-4223-a860-65e23373eab4}annualfee'],
                          " BPS"
                        ),
                        ""
                      ),
                      saveInto: {
                        a!save(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{796cea1b-ff7a-4223-a860-65e23373eab4}annualfee'],
                          if(
                            or(isnull(save!value), save!value = ""),
                            null,
                            tointeger(save!value)
                          )
                        ),
                        a!save(ri!feeDetails, local!feeDetails),
                        a!save(ri!allfeeDetails, ri!feeDetails)
                      },
                      align: "LEFT"
                    ),
                    a!textField(
                      validations: {
                        if(
                          contains(
                            { "Next", "First", "Over" },
                            fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{08ad88f5-e074-43e5-856e-a3661bdc2ee3}sequence']
                          ),
                          {},
                          "Sequence should not be empty and Only First, Next, Over sequence allowed"
                        ),
                        if(
                          a!isNullOrEmpty(
                            fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{08ad88f5-e074-43e5-856e-a3661bdc2ee3}sequence']
                          ),
                          "Sequence should not be empty",
                          {}
                        )
                      },
                      value: fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{08ad88f5-e074-43e5-856e-a3661bdc2ee3}sequence'],
                      saveInto: {
                        fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{08ad88f5-e074-43e5-856e-a3661bdc2ee3}sequence'],
                        a!save(ri!feeDetails, local!feeDetails),
                        a!save(ri!allfeeDetails, ri!feeDetails)
                      },
                      readOnly: not(ri!isEdit),
                      align: "LEFT"
                    ),
                    a!textField(
                      validations: if(
                        or(
                          a!isNullOrEmpty(
                            fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount']
                          ),
                          tointeger(
                            fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount']
                          ) = cons!WMS_INT_ZERO
                        ),
                        "Please enter a valid dollar amount.",
                        {}
                      ),
                      readOnly: not(ri!isEdit),
                      value: if(
                        a!isNotNullOrEmpty(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount']
                        ),
                        dollar(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount']
                        ),
                        dollar(0)
                      ),
                      saveInto: {
                        a!save(
                          fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount'],
                          if(
                            a!isNotNullOrEmpty(save!value),
                            save!value,
                            0
                          )
                        ),
                        a!save(ri!feeDetails, local!feeDetails),
                        a!save(ri!allfeeDetails, ri!feeDetails)
                      },
                      align: "LEFT"
                    ),
                    a!richTextDisplayField(
                      value: a!richTextIcon(
                        showWhen: contains(
                          {
                            cons!PRC_REF_ID_STAGE_IN_REVIEW,
                            cons!PRC_REF_ID_STAGE_RETURNED_RESUBMITTED_PRICING,
                            cons!PRC_REF_ID_STAGE_REVIEW_PRICING
                          },
                          tointeger(
                            ri!prcRequest['recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{f3e4d721-201d-4797-a17a-cfec05ef3e98}stage']
                          )
                        ),
                        icon: "close",
                        altText: "delete ",
                        caption: "Remove",
                        link: a!dynamicLink(
                          value: fv!index,
                          saveInto: {
                            a!save(
                              local!feeDetails[fv!index]['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{be1056cb-8331-4446-8fa4-3081fc64bc73}isactive'],
                              false()
                            ),
                            a!save(ri!feeDetails, local!feeDetails),
                            a!save(ri!allfeeDetails, ri!feeDetails)
                          }
                        ),
                        linkStyle: "STANDALONE",
                        color: "NEGATIVE"
                      )
                    )
                  }
                ),
                {}
              )
            ),
            addRowLink: a!dynamicLink(
              showWhen: contains(
                {
                  cons!PRC_REF_ID_STAGE_IN_REVIEW,
                  cons!PRC_REF_ID_STAGE_RETURNED_RESUBMITTED_PRICING,
                  cons!PRC_REF_ID_STAGE_REVIEW_PRICING
                },
                tointeger(
                  ri!prcRequest['recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{f3e4d721-201d-4797-a17a-cfec05ef3e98}stage']
                )
              ),
              label: "Add Tier Schedule",
              value: {},
              saveInto: {
                a!save(
                  local!feeDetails,
                  append(
                    local!feeDetails,
                    'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee'(
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{796cea1b-ff7a-4223-a860-65e23373eab4}annualfee': null(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{67613804-ab49-4df7-91d4-358b515efd47}minimumfee': local!minimumValue,
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7fed9839-24ea-47a8-b23b-4cc6245daff8}amount': null(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{08ad88f5-e074-43e5-856e-a3661bdc2ee3}sequence': null(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4a8a03ee-98f5-4712-8135-4c235968e033}serviceExId': ri!services['recordType!{471f50a7-6d9a-4e1b-a1ae-4b84239a4583}PRC Services.fields.{15ae6ce2-ff70-48b8-ac87-a04a0bb310b9}serviceExtId'],
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{6e4fe629-03b7-49fe-8d52-f541257e3ca5}planId': tointeger(
                        index(
                          ri!selectedPlan,
                          'recordType!{3b41856e-be2b-486e-b0f7-09436ce2d07e}PRC Plan.fields.{4903a64b-b0f8-4ddb-98d1-00bcc0e648d1}prcPlanId',
                          {}
                        )
                      ),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{30de7239-941c-401f-ad56-2672421eba71}scenarioId': tointeger(
                        index(
                          ri!selectedScenario,
                          'recordType!{94f6f945-ec9c-4178-8b3f-684a5547bb00}PRC Scenarios.fields.{ad9e991c-6487-437f-8665-fe15a96eba42}prcScenarioId',
                          {}
                        )
                      ),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{fcc63a8b-7dab-4ea1-b0c5-61269e0ff801}createdby': loggedInUser(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{7e014768-277f-4844-a8d0-7c6baeccf934}iteration': ri!iteration,
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{0e58f0ed-17dc-4b31-8622-5f0a01f59e11}createdon': now(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{be1056cb-8331-4446-8fa4-3081fc64bc73}isactive': true(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{ff8a31de-a89c-4848-b7b4-20726b0a81b9}updatedby': loggedInUser(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{f18ed932-7461-403c-9bde-5580a9831588}updatedon': now(),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{e1f9189a-a80d-4454-b39d-d1b91be1a1ce}prcRequestId': index(
                        ri!prcRequest,
                        'recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{2e588546-edee-47b5-a888-9e8813bbf0d4}prcRequestId',
                        {}
                      ),
                      'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{086743c7-671f-44b9-83ce-4978ed1e0403}wmsRequestId': ri!prcRequest['recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{010c7913-357e-4e1e-8858-7a6a1b7525cd}wmsRequestId']
                    )
                  )
                ),
                a!save(ri!feeDetails, local!feeDetails),
                a!save(ri!allfeeDetails, ri!feeDetails)
              }
            )
          ),
          divider: "NONE"
        ),
        rule!WMS_VerticalSpacer(n: 3),
        a!sideBySideLayout(
          items: a!sideBySideItem(
            width: "MINIMIZE",
            item: a!textField(
              label: "Minimum Fee",
              labelPosition: "JUSTIFIED",
              readOnly: not(ri!isEdit),
              value: if(
                isnull(todecimal(local!minimumValue)),
                dollar(todecimal(0)),
                dollar(todecimal(local!minimumValue))
              ),
              saveInto: {
                /* Save into the first row */
                a!save(
                  local!minimumValue,
                  if(
                    a!isNotNullOrEmpty(save!value),
                    save!value,
                    0
                  )
                ),
                /* Update all matching rows */
                a!save(
                  local!minimumFee,
                  a!forEach(
                    items: reject(fn!isnull, local!minimumFee),
                    expression: a!update(
                      data: fv!item,
                      index: 'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{67613804-ab49-4df7-91d4-358b515efd47}minimumfee',
                      value: if(
                        a!isNotNullOrEmpty(save!value),
                        save!value,
                        0
                      )
                    )
                  )
                ),
                /* Update original feeDetails */
                a!save(
                  local!feeDetails,
                  a!forEach(
                    items: local!feeDetails,
                    expression: a!localVariables(
                      local!match: index(
                        local!minimumFee,
                        wherecontains(
                          tointeger(
                            fv!item['recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4b8a7034-4307-4a3d-8a34-aff1a0dcdfd5}prcservicesvmapid']
                          ),
                          tointeger(
                            index(
                              local!minimumFee,
                              'recordType!{f6895dd9-7b01-4146-a52e-be727fef79d3}PRC Vmap Service Fee.fields.{4b8a7034-4307-4a3d-8a34-aff1a0dcdfd5}prcservicesvmapid',
                              {}
                            )
                          )
                        ),
                        {}
                      ),
                      if(
                        a!isNotNullOrEmpty(local!match),
                        local!match,
                        fv!item
                      )
                    )
                  ),
                  
                ),
                a!save(ri!feeDetails, local!feeDetails),
                a!save(ri!allfeeDetails, ri!feeDetails)
              },
              align: "LEFT"
            )
          )
        ),
        a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "close",
              icon: "check",
              style: "SOLID",
              value: false,
              saveInto: ri!showFeeDetails,
              
            ),
            a!buttonWidget(
              label: "Submit",
              icon: "check",
              style: "SOLID",
              value: false,
              saveInto: {
                ri!showFeeDetails,
                a!startProcess(
                  isSynchronous: true(),
                  processModel: cons!PRC_WRITE_TO_VMAP_FEE_DETAILS,
                  processParameters: {
                    feeDetailsProspect: ri!allfeeDetails,
                    prcRequest: ri!prcRequest,
                    prcServices: ri!allServices
                  },
                  onSuccess: {
                    a!save(
                      local!feeDetails,
                      fv!processInfo.pv.RecordsUpdated1
                    ),
                    a!save(ri!feeDetails, local!feeDetails),
                    a!save(ri!allfeeDetails, ri!feeDetails)
                  },
                  
                )
              },
              showWhen: contains(
                {
                  cons!PRC_REF_ID_STAGE_IN_REVIEW,
                  cons!PRC_REF_ID_STAGE_RETURNED_RESUBMITTED_PRICING,
                  cons!PRC_REF_ID_STAGE_REVIEW_PRICING
                },
                tointeger(
                  ri!prcRequest['recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{f3e4d721-201d-4797-a17a-cfec05ef3e98}stage']
                )
              )
            ),
            
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              icon: "times",
              style: "SOLID",
              value: false(),
              saveInto: ri!showFeeDetails,
              showWhen: contains(
                {
                  cons!PRC_REF_ID_STAGE_IN_REVIEW,
                  cons!PRC_REF_ID_STAGE_RETURNED_RESUBMITTED_PRICING,
                  cons!PRC_REF_ID_STAGE_REVIEW_PRICING
                },
                tointeger(
                  ri!prcRequest['recordType!{9ffd9a48-c615-4180-a5a0-1782cd09348f}PRC Request.fields.{f3e4d721-201d-4797-a17a-cfec05ef3e98}stage']
                )
              )
            )
          }
        )
      },
      showWhen: ri!showFeeDetails
    )
  }
)

  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    Making some tweaks to the expression for addRowLink can help achieve the expected. 
    Here is a sample pattern you can refer which has two additional local variables and some changes to addRowLink definition so that expected functionality can be reached. 

    a!localVariables(
      /*  
      * local!employess is provided in this recipe as a way to start with hard-coded
      * data. However, this data is identical to the data created from the entity-backed
      * tutorial. Replace the hard-coded data with a query to the employee data store
      * entity and all of the employee records from the tutorial will appear.
      *
      * To replace this data with your own, replace (ctrl+H or cmd+H) all references to
      * local!employees with your data source, either via rule input or local variable.
      */
      local!employees: {
        a!map( id: 1, firstName: "John" , lastName: "Smith" , department: "Engineering" , title: "Director" , phoneNumber: "555-123-4567" , startDate: today()-360 ),
        a!map( id: 2, firstName: "Michael" , lastName: "Johnson" , department: "Finance" , title: "Analyst" , phoneNumber: "555-987-6543" , startDate: today()-360 ),
        a!map( id: 3, firstName: "Mary", lastName: "Reed" , department: "Engineering" , title: "Software Engineer" , phoneNumber: "555-456-0123" , startDate: today()-240 ),
      },
     local!lastRow,local!newRow,
      a!formLayout(
        titleBar: "Example: Add,Update, or Remove Employee Data",
        contents: {
          a!gridLayout(
            totalCount: count(local!employees),
            headerCells: {
              a!gridLayoutHeaderCell(label: "First Name" ),
              a!gridLayoutHeaderCell(label: "Last Name" ),
              a!gridLayoutHeaderCell(label: "Department" ),
              a!gridLayoutHeaderCell(label: "Title" ),
              a!gridLayoutHeaderCell(label: "Phone Number" ),
              a!gridLayoutHeaderCell(label: "Start Date", align: "RIGHT" ),
              /* For the "Remove" column */
              a!gridLayoutHeaderCell(label: "" )
            },
            /* Only needed when some columns need to be narrow */
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:2 ),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            /*
            * a!forEach() will take local!employee data and used that data to loop through an
            * expression that creates each row.
            *
            * When modifying the recipe to work with your data, you only need to change:
            * 1.) the number of fields in each row
            * 2.) the types of fields for each column (i.e. a!textField() for text data elements)
            * 3.) the fv!item elements. For example fv!item.firstName would change to fv!item.yourdata
            */
            rows: a!forEach(
              items: local!employees,
              expression: a!gridRowLayout(
                contents: {
                  /* For the First Name Column*/
                  a!textField(
                    /* Labels are not visible in grid cells but are necessary to meet accessibility requirements */
                    label: "first name " & fv!index,
                    value: fv!item.firstName,
                    saveInto: fv!item.firstName,
                    required: true
                  ),
                  /* For the Last Name Column*/
                  a!textField(
                    label: "last name " & fv!index,
                    value: fv!item.lastName,
                    saveInto: fv!item.lastName,
                    required:true
                  ),
                  /* For the Department Column*/
                  a!dropdownField(
                    label: "department " & fv!index,
                    placeholder: "-- Select -- ",
                    choiceLabels: { "Corporate", "Engineering", "Finance", "Human Resources", "Professional Services", "Sales" },
                    choiceValues: { "Corporate", "Engineering", "Finance", "Human Resources", "Professional Services", "Sales" },
                    value: fv!item.department,
                    saveInto: fv!item.department,
                    required:true
                  ),
                  /* For the Title Column*/
                  a!textField(
                    label: "title " & fv!index,
                    value: fv!item.title,
                    saveInto: fv!item.title,
                    required:true
                  ),
                  /* For the Phone Number Column*/
                  a!textField(
                    label: "phone number " & fv!index,
                    placeholder:"555-456-7890",
                    value: fv!item.phoneNumber,
                    saveInto: fv!item.phoneNumber
                  ),
                  /* For the Start Date Column*/
                  a!dateField(
                    label: "start date " & fv!index,
                    value: fv!item.startDate,
                    saveInto: fv!item.startDate,
                    required:true,
                    align: "RIGHT"
                  ),
                  /* For the Removal Column*/
                  a!richTextDisplayField(
                    value: a!richTextIcon(
                      icon: "close",
                      altText: "delete " & fv!index,
                      caption: "Remove " & fv!item.firstName & " " & fv!item.lastName,
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(local!employees, remove(local!employees, save!value))
                        }
                      ),
                      linkStyle: "STANDALONE",
                      color: "NEGATIVE"
                    )
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Employee",
              /*
               * For your use case, set the value to a blank instance of your CDT using
               * the type constructor, e.g. type!Employee(). Only specify the field
               * if you want to give it a default value e.g. startDate: today()+1.
               */
              value: {
                startDate: today() + 1
              },
              saveInto: {
                a!save(local!lastRow,local!employees[length(local!employees)]),
                a!save(local!employees, append(local!employees, save!value)),
                
                a!save(local!newRow,save!value),
                a!save(local!employees,a!update(
                  local!employees,{length(local!employees),length(local!employees)-1},
                  {local!lastRow,local!newRow}))
                
                
              }
            ),
            rowHeader: 1
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            submit: true
          )
        )
      )
    )
    

  • Thanks , Harshitha . I will check this approach , tried with insert function it also seems to work for now. 

  • 0
    Certified Lead Developer
    in reply to iswaryan3520

    Oh yes insert() is great for this! can't believe why my mind skipped it. Anyway glad you got the expected results.