Duplicate check in a dynamic grid layout

Hi, I have a text field in dynamic grid layout. How do i check for a duplicate entry and generate a error message in validation?

(I'm storing the entries from the text field in a rule input of cdt type)

  Discussion posts and replies are publicly visible

Parents Reply Children
  • Hi Arpit,

    That was a really short version of that and worked completely fine. There's just a slight change for multiple cdt though.

    For multiple cdt instead of replacing fv!index we can replace the index function all together with the column name.
    Here's what it it looks like for me for multiple cdt,

    if(count(wherecontains(fv!item.(columnName), ri!array.(columnName))) > 1
    ,"Duplicate",
    {}
    )

    Please ignore the brackets with column name.

    Regards,
    Mohit Shah
  • Hi Arpit

      a!localVariables(
        local!data:rule!D_Demo_excel_Data(data:ri!input),
        {
          
          a!gridLayout(
            label: "Student Data",
            labelPosition: "ABOVE",
            headerCells: {
              a!gridLayoutHeaderCell(label: "Roll_No"),
              a!gridLayoutHeaderCell(label: "Name"),
              a!gridLayoutHeaderCell(label: "Subject_1"),
              a!gridLayoutHeaderCell(label: "Subject_2"),
              a!gridLayoutHeaderCell(label: "Subject_3"),
              a!gridLayoutHeaderCell(label: "Subject_4"),
              a!gridLayoutHeaderCell(label: "Total_Percentage"),
              a!gridLayoutHeaderCell(label: "Grade"),
            },
            columnConfigs: {},
            rows: {
              a!forEach(
                items: ri!data,
                expression: a!localVariables(
                  a!gridRowLayout(
                    contents: {
                      a!integerField(
                        value: fv!item.Roll_No,
                        saveInto: fv!item.Roll_No,
                        readOnly: true
                      ),
                      a!textField(
                        value: fv!item.Name,
                        saveInto: {fv!item.Name,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                        required: true
                      ),
                      a!integerField(
                        value: fv!item.Subject_1,
                        saveInto: {fv!item.Subject_1,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                        required: true
                      ),
                      a!integerField(
                        value: fv!item.Subject_2,
                        saveInto: {fv!item.Subject_2,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                        required: true
                      ),
                      a!integerField(
                        value: fv!item.Subject_3,
                        saveInto: {fv!item.Subject_3,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                        required: true
                      ),
                      a!integerField(
                        value: fv!item.Subject_4,
                        saveInto: {fv!item.Subject_4,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                        required: true
                      ),
                      a!integerField(
                        value:
                        {((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4},
                        /*saveInto:fv!item.Total_Percentage,*/
                       readOnly: true(),
                        required: true
                      ),
                      a!textField(
                        value: rule!D_excelGrade(percentage:fv!item.Total_Percentage),
                        /*saveInto:fv!item.Grade,*/
                        readOnly: true(),
                        required: true
                      ),
                    }
                  )
                )
              )
            },
            selectionSaveInto: {},
            validations: {},
            shadeAlternateRows: true
          ),
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "save",
    
                
                submit: true,
                style: "NORMAL"
              )
            },
            align: "START"
          )
          
        }
       
      )
    

    I am Getting the data from a excel file and writing it to the DB. but i want to check for duplicate, like if users enters the same record they must not be written in to the DB.