Using writeRecord smart service to write multiple records of one recordType .

Hello:

I am trying to use a!writeRecords() to write a list of records (of the same recordType) to the DB and it is writing a column of one-field to each field in the DB (images below).  The debugging section shows the values before I click on 'Submit'.  The second image is the data in the DB (Data Preview screen).

My understanding was that a!writeRecords smart service would insert two records - one for each row of information.  Obviously, I am not correct in my understanding of the service.   How do I get each row to be written as a record in the DB?

As always, thanks for the help!

a!localVariables(
  local!userSelection: null(),
  local!ListOfOptions: rule!FST_getGuidelines(),
  local!ListOfChoiceValues: enumerate(length(local!ListOfOptions)) + 1,
  local!ListOfCategories: {},
  a!formLayout(
    label: "Category Management",
    contents: {
      rule!FST_UserSelection(
        ListOfOptions: local!ListOfOptions,
        ListOfChoiceValues: local!ListOfChoiceValues,
        label: "Select Guideline",
        userChoiceValue: local!userSelection
      ),

      a!sectionLayout(
        marginAbove: "MORE",
        marginBelow: "NONE",
        showWhen: a!isNotNullOrEmpty(local!userSelection),
        label: "Define Categories",
        contents: {
          a!gridLayout(
            rowHeader: 1,
            emptyGridMessage: "No categories defined",
            headerCells: {
              a!gridLayoutHeaderCell(label: "Category Name"),
              a!gridLayoutHeaderCell(
                label: "Description - Examples of items in category"
              ),
              a!gridLayoutHeaderCell(label: ""),
              /*--- column for remove/delete icon ---*/
              
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 1),
              a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 3),
              a!gridLayoutColumnConfig(width: "ICON")
            },
            rows: {
              a!forEach(
                items: local!ListOfCategories,
                expression: a!gridRowLayout(
                  contents: {
                    /* For the category Column*/
                    a!textField(
                      /* Labels are not visible in grid cells but are necessary to meet accessibility requirements */
                      label: "category " & fv!index,
                      value: fv!item['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName'],
                      saveInto: fv!item.['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName'],
                      required: true
                    ),
                    /* For the category description Column*/
                    a!textField(
                      label: "category description " & fv!index,
                      value: fv!item['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{124c6a28-7f89-4e04-887f-1d13e1adad0e}categoryDefinition'],
                      saveInto: fv!item['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{124c6a28-7f89-4e04-887f-1d13e1adad0e}categoryDefinition'],
                      required: true
                    ),
                    a!richTextDisplayField(
                      value: a!richTextIcon(
                        icon: "times",
                        altText: "Delete " & fv!index,
                        caption: "Remove " & fv!item['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName'],
                        link: a!dynamicLink(
                          value: remove(local!ListOfCategories, fv!index),
                          saveInto: local!ListOfCategories
                          /*value:fv!index,*/
                          /*saveInto: {a!save(local!ListOfCategories, remove(local!ListOfCategories, save!value))}*/
                        ),
                        linkStyle: "STANDALONE",
                        color: "NEGATIVE"
                      )
                    )
                  },
                  
                )
              )
            },
            addRowLink: a!dynamicLink(
              label: "Add Another Category",
              value: append(
                local!ListOfCategories,
                'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category'(
                  'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName': null,
                  'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{124c6a28-7f89-4e04-887f-1d13e1adad0e}categoryDefinition': null,
                  
                )
              ),
              saveInto: local!ListOfCategories
            ),
            
          )
        }
      ),
      
      /*--- debugging ----*/
      a!sectionLayout(
        marginAbove: "MORE",
        label:"Debugging:",
        contents: {
          a!textField(
          align:"LEFT",
          label:"Guideline Choice",
          labelPosition: "JUSTIFIED",
          readOnly: true(),
          value:local!userSelection
        ),
        a!textField(
          label: "Current Category List:",
          labelPosition: "JUSTIFIED",
          align: "LEFT",
          value: local!ListOfCategories,
          readOnly: true()
        ),
        }
      )
    },
    
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true,
          style: "PRIMARY",
          loadingIndicator: true,
          saveInto: {
            a!writeRecords(
              records: 'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category'(
                'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName': local!ListOfCategories['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{599d40a4-73ed-4cd5-a93e-4aa2739197f4}categoryName'],
                'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{124c6a28-7f89-4e04-887f-1d13e1adad0e}categoryDefinition': local!ListOfCategories['recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{124c6a28-7f89-4e04-887f-1d13e1adad0e}categoryDefinition'],
                'recordType!{533fa657-125c-4f6e-b915-cd29291c4c91}FST Category.fields.{b0ea631f-738c-40ed-8485-bc12af93a7fa}guidelineReference': tostring(
                  local!ListOfOptions,
                  local!userSelection
                )
              ),
              
            )
          }
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: {},
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Associate Developer

    Hi,
    1. you have 2 rows of data as per screenshot and you are not indexing it while using write to record smart service 
      ->  local!ListOfCategorie[categoryName] will give list of string instead of string and same for second field  (line:129 and 130)
    if you want to write multiple records at once , this method will not work , you can pass local!ListOfCategorie directly to records parameter , this will work fine as long as your local variable is a record type 
    example : -

    a!localVariables(
      local!data:a!forEach(
        items: enumerate(3)+1,
        expression: 'recordType!{dfd8b053-0620-45a1-b138-ee4c1496b8a2}HRMS Event'(
        'recordType!{dfd8b053-0620-45a1-b138-ee4c1496b8a2}HRMS Event.fields.{0230c10d-212c-4c2e-b1e7-a842f5010519}eventbodytxt': tostring(fv!item)
      )),
      {
        a!buttonArrayLayout(
          buttons: {
            a!buttonWidget(
              label: "Button",
              style: "NORMAL",
              saveInto:   a!writeRecords(
                records: local!data
              )
            )
          },
          align: "START"
        )
      }
    
    )
       

    2. can you please explain your line:131-133.

  • Eren,

    line 131-133 should have been commented out. 

    Thanks - for the response.  Guess, I just had to use the local variable to write all the records instead of the way I had written it.

    Ma

  • Thanks a lot for information! That's might help me! So math websites that show work are highly valuable to students. They offer a structured approach to solving math problems, breaking them down into manageable steps. This not only aids in completing assignments but also promotes a deeper understanding of mathematical concepts, making it an indispensable learning tool.

Reply Children
No Data