Saving editable grid

Hello Team,

I have build an editable grind and now I want to save the values inside my records. I have record table and rule input in my interface the problem is how I can save this data for each request I have. The data is a sample there are around 15 rows which I want the user to be able to save some of them can be null some of them can be filled out. Basically the property is read only, once user enter value we can use a!save to save the property for the respective row, but I always get cannot index rule input records..

rows: {
                            a!gridRowLayout(
                              contents: {
                                a!richTextDisplayField(
                                  labelPosition: "COLLAPSED",
                                  value: {
                                    a!richTextItem(
                                      text: {"Melting Point"}
                                    )
                                  }
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  disabled: false,
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"g/cm3", "kg/m3"},
                                  choiceValues: {"g/cm3", "kg/m3"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "Select",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  validations: {}
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"℃", "℉"},
                                  choiceValues: {"℃", "℉"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "Select",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"Property has not been measured"},
                                  choiceValues: {"Property has not been measured"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "--- Select a Value ---",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                )
                              },
                              showWhen: if(
                                or(
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = "LIquid",
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = "Solid",
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = ""
                                ),
                                true,
                                false)
                            ),
                            a!gridRowLayout(
                              contents: {
                                a!richTextDisplayField(
                                  labelPosition: "COLLAPSED",
                                  value: {
                                    a!richTextItem(
                                      text: {"Freezing Point"}
                                    )
                                  }
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  disabled: false,
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"g/cm3", "kg/m3"},
                                  choiceValues: {"g/cm3", "kg/m3"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "Select",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  validations: {}
                                ),
                                a!textField(
                                  label: "Text",
                                  labelPosition: "ABOVE",
                                  saveInto: {},
                                  refreshAfter: "UNFOCUS",
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"℃", "℉"},
                                  choiceValues: {"℃", "℉"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "Select",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                ),
                                a!dropdownField(
                                  choiceLabels: {"Property has not been measured"},
                                  choiceValues: {"Property has not been measured"},
                                  label: "Dropdown",
                                  labelPosition: "ABOVE",
                                  placeholder: "--- Select a Value ---",
                                  saveInto: {},
                                  searchDisplay: "AUTO",
                                  validations: {}
                                )
                              },
                              showWhen: if(
                                or(
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = "LIquid",
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = "Solid",
                                  ri!AOS_PhysChem['recordType!{1ddc2dbc-133e-49a3-a416-3e896db0beb4}AOS_Phys_chem.fields.{6862862b-7cbf-4b5d-be70-7944f6a23f5b}PhysicalState'] = ""
                                ),
                                true,
                                false)
                            ),
                            a!gridRowLayout(
                              contents: {
                                a!richTextDisplayField(
                                  labelPosition: "COLLAPSED",
                                  value: {
                                    a!richTextItem(
                                      text: {"Boiling Point"}
                                    )
                                  }
                                ),

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    This may be occurring due to the direct [ ] indexing. Try Using the property or Index function.

  • Can you give me an example with the full code which I provided in my previous comment. Thank you!

  • If you can give me an idea how to do that would be great!

    "Why isn't the property stored in the array-row's data and displayed there"

  • 0
    Certified Lead Developer
    in reply to Shwapx
    If you can give me an idea how to do that would be great!

    It sounds as if you mean to have 17 rows of data in that particular record type.  You would therefore initialize the rows in advance, setting each row to one of your desired "property" settings (i assume this is "melting point", "freezing point", etc).  Then your grid could merely call a!forEach over all 17 rows of initialized data and display the needed rows.  Further logic could discern whether any given row (or individual fields within it) should be treated differently depending on what the given property is, or other settings saved within that row's data per what the user's filled out.

  • Yes this is exactly what i need, but there is the issue I have never done that and i'm not quite sure how to:

    "You would therefore initialize the rows in advance, setting each row to one of your desired "property" settings (i assume this is "melting point", "freezing point", etc)"

  • 0
    Certified Lead Developer
    in reply to Shwapx

    Well, being able to initialize an array of RecordType data is really one of the simpler things you should learn about before attempting to do a (imho) somewhat complicated grid operation on them...

    recordType data offers the unique challenge of not simply being able to create a local dummy and send you an example, however for the moment i've made a VERY rough example while using a generic "personnel" record type from my CE site (and we can pretend the "firstName" field is the one that should store the property, for the purposes of this).  Here we start with an array of the various "properties", then merely loop over it, setting the recordType field to the current iteration's value.  You can see here the result is a list of that recordType initialized with just that value set in each item.

  • +1
    Certified Lead Developer
    in reply to Mike Schmitt

    Depending on your needs, you could do the above initialization either in the process prior to your form, or on your form itself. 

    For the sake of argument I've gone ahead and mocked up this simplified example grid with the first 2 "properties" from my example above, but now displayed on an on-form grid and ready to accept changes to the "value" column (saved into the "lastName" recordtype property since this is still my "personnel" record type).

    a!localVariables(
    
      local!properties: {
        "freezing point",
        "melting point"
      },
    
      local!initialRowData: a!forEach(
        local!properties,
    
        'recordType!{...}Personnel'(
          'recordType!{...}Personnel.fields.{firstName}firstName': fv!item
        )
      ),
      
      
      a!gridLayout(
        label: "Items",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Property"),
          a!gridLayoutHeaderCell(label: "Value")
        },
        
        rows: a!forEach(
          local!initialRowdata,
          
          a!gridRowLayout(
            contents: {
              a!richTextDisplayField(
                value: a!richTextItem(
                  text: fv!item['recordType!{...}Personnel.fields.{firstName}firstName']
                )
              ),
              
              a!textField(
                value: fv!item['recordType!{...}Personnel.fields.{lastName}lastName'],
                saveInto: fv!item['recordType!{...}Personnel.fields.{lastName}lastName']
              )
            }
          )
        )
      )
    )

  • Okay did that and now I need to pass that to my rule input?:


  • It's working in local!variable, but i need to pass this to rule input so i can pass that data in my other interfaces.

  • 0
    Certified Lead Developer
    in reply to Shwapx

    Depends on how you've initialized it - if you did it in a PV, simply pass the PV value into your form (and back out into your process again).  If you'd rather initialize as a local variable like here (easiest if you want the interface easily testable), then have your Submit button save a copy of the local variable's final state into a Rule Input (set as an array of your record type), to be passed back out into your process.

  • I think I was able to achieve what I need. Thank you for the help! The only thing left is how to hide specific rows based on selection from text field.

    Maybe the easiest way would be to have 3 different local variables and based on the field use that in the grid not sure if i can have if function after the for each where i define the localvariable.

  • 0
    Certified Lead Developer
    in reply to Shwapx
    hide specific rows based on selection from text field.

    i'm still fuzzy on what "text field" you mean.  I'd point out that you can always utilize the "showWhen" parameter within the a!gridRowLayout() rule, inside the a!forEach() call, naming whatever logic you need to show or hide that row depending on what the current row's value contains.  I'd caution that showing/hiding a row based on an input in that row, though, can be troublesome since you could find yourself in a situation where a user accidentally selects a value that causes the row to be hidden, then the row goes away, and they have no way to bring it back (since it's now hidden).  But as long as this is carefully managed then it should be able to be used fine.

Reply
  • 0
    Certified Lead Developer
    in reply to Shwapx
    hide specific rows based on selection from text field.

    i'm still fuzzy on what "text field" you mean.  I'd point out that you can always utilize the "showWhen" parameter within the a!gridRowLayout() rule, inside the a!forEach() call, naming whatever logic you need to show or hide that row depending on what the current row's value contains.  I'd caution that showing/hiding a row based on an input in that row, though, can be troublesome since you could find yourself in a situation where a user accidentally selects a value that causes the row to be hidden, then the row goes away, and they have no way to bring it back (since it's now hidden).  But as long as this is carefully managed then it should be able to be used fine.

Children