Passing data to a CDT from a editable grid

Certified Senior Developer

Hello! 

I am working on an interface which shows a editable grid. The grid gets data from a expression rule , which I pass to interface using a local variable. 

Now I want to save the values showed in the grid to the CDT (rule input), but save function doesn't seems to work for me. the rule input is still null. 

Which is the best practice to do that? Or is another way to pass directly the value load into a local variable to rule input?

Thank you

a!localVariables(
  local!user:rule!MV_readCSVcontent(
    if(
    isnull(ri!day),
    today()-1,
    ri!day)),
  local!exportDocId ,
  local!errorMessage  ,
 
 
 
  { 
    
    a!sectionLayout(
      label: "",
      contents: {
        a!sideBySideLayout(
          items: {
            a!sideBySideItem(
              item: a!dateField(
                label: "Date",
                labelPosition: "ABOVE",
                value:ri!day,
                saveInto: ri!day,
                validations: if(
                  ri!day>=today(),
                  "This day is in the future. Please select a past day",

                  if(
                    ri!day < (today()-30),
                    "Can not select a day before 30 days from today",
                    {}
                    
                  )
                ) 
              )
            )
            
          
          }
        )
      }
     
    ),
    
    a!gridLayout(
      label: "grid",
      labelPosition: "COLLAPSED",
      headerCells: {
        a!gridLayoutHeaderCell(label: "Username")
        
      },
      columnConfigs: {
        a!gridLayoutColumnConfig(
          width: "DISTRIBUTE"
        )
       
      },
      rows: {
        a!forEach(
          items: local!user,
          expression:{
            a!gridRowLayout(
              id:fv!index,
              contents: {
                a!textField(
                  label: "Username",
                  value: fv!item,
                  saveInto:  a!save(ri!users.username, fv!item,)
                  
                )
               
              }
            )
          }
        )
      },
      selectionSaveInto:  a!forEach(
        items:local!user,
        expression: a!save(ri!users, local!user)
      ),
      
      showwhen: if(isnull(ri!day),
      false(),
      true()),
      validations: {},
      shadeAlternateRows: true,
      
    ),
    {
      if(
        isnull(local!exportDocId),
        a!linkField(
          labelPosition: "COLLAPSED",
          links: a!dynamicLink(
            label: "Export to Excel File",
            saveInto: {
              a!exportDataStoreEntityToExcel(
                entity: cons!MV_INACTIVE_USER,
                documentName: "Excel Export " & now(),
                saveInFolder: cons!MV_FolderDocumentReference,
                onSuccess: a!save(
                  local!exportDocId,
                  fv!newDocument
                ),
                onError: a!save(
                  local!errorMessage,
                  "Error Exporting File to Excel"
                )
              )
            }
          )
        ),
        {}
      ),
      if(

        not(isnull(local!exportDocId)),

        a!linkField(
          links: a!documentDownloadLink(
            label: "Download Excel File",
            document: local!exportDocId
          )
        ),
        a!textField(
          value: local!errorMessage,
          readOnly: true
        )
      ),
     
    },
    
    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          saveInto: a!save(ri!users,ri!users),
          submit: true,
          style: "PRIMARY"
        )
      }


      


    ),
    
    
   
  }
 
  
)

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    So I'm a little unclear whether local!user is intended to be a CDT similar to ri!user, or if it's just a list of usernames (i.e. text).  So for now I'm assuming it's only a list of usernames, based on the value: parameter of the text field in the grid row.

    I assume you're just trying to give the user a chance to enter any edits to a user in the grid, then save the result (with any changes) into the ri!users CDT, where the usernames are stored in the ".username" property of the CDT.  This save will occur during the button click, by looping over local!user and creating a dictionary for each item, and saving all of that into ri!users.  I'm not sure why you have a "selectionSaveInto", that doesn't appear needed so I've commented it out.

    Please see the example below, and note that I've removed a few irrelevant sections of the form - the only relevant changes are to the grid and to the submit button.  Though I've also cleaned up the formatting some.

    a!localVariables(
      local!user: rule!MV_readCSVcontent(
        if(
          isnull(ri!day),
          today() - 1,
          ri!day
        )
      ),
      local!exportDocId,
      local!errorMessage,
     
      { 
        /* section removed from example, no changes should be needed */
        
        a!gridLayout(
          label: "grid",
          labelPosition: "COLLAPSED",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Username")
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(
              width: "DISTRIBUTE"
            )
           
          },
          rows: {
            a!forEach(
              items: local!user,
              expression: {
                a!gridRowLayout(
                  id: fv!index,
                  contents: {
                    a!textField(
                      label: "Username",
                      value: fv!item,
                      saveInto: {
                        fv!item
                        /* a!save( */
                          /* ri!users.username, */
                          /* fv!item */
                        /* ) */
                      }
                    )
                  }
                )
              }
            )
          },
          /* selectionSaveInto:  a!forEach( */
            /* items: local!user, */
            /* expression: a!save(ri!users, local!user) */
          /* ), */
          
          showwhen: if(
            isnull(ri!day),
            false(),
            true()
          ),
          validations: {},
          shadeAlternateRows: true,
          
        ),
        
        /* link field removed from example, no changes should be needed */
        
        a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              saveInto: {
                a!save(
                  ri!users,
                  a!forEach(
                    local!users,
                    {
                      username: fv!item
                    }
                  )
                )
              },
              submit: true,
              style: "PRIMARY"
            )
          }
        ),
      }
    )

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Yes the local!user is just a list of string value. And your solution works . Thank you very much