Error trying to acumulate a value in an editable grid

Hi! I have created an editable grid in which the user can add a quantity to the "Cantidad Recepcionada" field. 

This value is saved in two records (Field: CantRecepAcum)

After this, I wanted that, each time the user runs the process and saves a new quantity, the value is added to the previous existing value of the field "CantRecepAcum"

In order to do this, I configured the following code in the interface (I save the value of fv!item in my rule input each time. Every time a user enters a value, there is a sum between the curren value of the ri! and the new value of fv!item, for the field "CPF_Lineas_Pedido_CantRecepAcum":

In the interface, when I click the submit button, it is not acumulating OK

(I´m going to try to explain. If I put 1,0 in the rows, both fields increment +1. If I continue with 1,0, its a +1 for each field too. But when I change and put 2,0, then the first field goes a +2 up and the second a +1. If I repeat then with 2,0, both fields go up +2. Its a little bit strange, and i just want each value to update separately)

Maybe I should do the operation inside the SaveInto Parameter of the integer field. Is it possible to make a loop there? (Save the fv!item+ the previous value)

Thanks a lot!

My code is below:

a!localVariables(
  local!DatosLineas: a!queryRecordType(
    recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
    fields: {
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fcfa4b36-4398-4430-8055-ecfa59daf13a}idLineaPedido',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{69e9a834-b2fb-4f35-a36d-3c526c97f4ac}Material',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{7fd4a6cb-f5b7-4f0f-9f86-1680005f8be5}CantidadPdteRecep',
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{2da9182e-b3ef-4ef1-abfa-53d4df63d33c}idUnico'
    },
    filters: a!queryFilter(
      field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
      operator: "=",
      value: ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{7309402c-2312-4a4e-bdaa-5654789bffb2}idPedido']
    ),
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100)
  ).data,
  local!DatosLineas2: {},
  local!DatosLineas3: {},
  local!CantRecep: a!queryRecordType(
    recordType: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido',
    fields: {
      'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum'
    },
    filters: {
      a!queryFilter(
        field: 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido',
        operator: "=",
        value: ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{7309402c-2312-4a4e-bdaa-5654789bffb2}idPedido']
      )
    },
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100)
  ).data,
  {
    a!sectionLayout(
      label: "Datos Recepción",
      labelIcon: "dolly",
      contents: {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Id Recepción",
                  labelPosition: "ABOVE",
                  value: ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{cb86a21e-a5e5-4ec7-98dc-14e94cc5736c}idRecepcion'],
                  saveInto: ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{cb86a21e-a5e5-4ec7-98dc-14e94cc5736c}idRecepcion'],
                  refreshAfter: "UNFOCUS",
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!textField(
                  label: "Id Pedido",
                  labelPosition: "ABOVE",
                  value: ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{7309402c-2312-4a4e-bdaa-5654789bffb2}idPedido'],
                  saveInto: ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{4f22f1d7-f5cd-446a-90a2-64a5893f912b}idPedido'],
                  refreshAfter: "UNFOCUS",
                  validations: {}
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!dateTimeField(
                  label: "Fecha y hora de Recepción",
                  labelPosition: "ABOVE",
                  value: ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{4fa92044-3c8b-438b-b77e-30bf88efbae3}FechaRecepcion'],
                  saveInto: ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{4fa92044-3c8b-438b-b77e-30bf88efbae3}FechaRecepcion'],
                  validations: {}
                )
              }
            )
          }
        )
      }
    ),
    a!sectionLayout(
      label: "Líneas Recepción",
      labelIcon: "list-alt-solid",
      contents: {
        a!gridLayout(
          label: "A continuación, introduzca las cantidades a recepcionar para cada línea de pedido y pulse el botón de Recepción",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Linea Pedido"),
            a!gridLayoutHeaderCell(label: "Pedido"),
            a!gridLayoutHeaderCell(label: "Material"),
            a!gridLayoutHeaderCell(label: "Cantidad Pendiente"),
            a!gridLayoutHeaderCell(label: "Precio Unitario"),
            a!gridLayoutHeaderCell(label: "Cantidad Recepcionada")
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "ICON")
          },
          rows: a!forEach(
            items: local!DatosLineas,
            expression: a!gridRowLayout(
              contents: {
                a!textField(value: fv!index, readOnly: true),
                a!textField(
                  value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido'],
                  readOnly: true
                ),
                a!textField(
                  value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{69e9a834-b2fb-4f35-a36d-3c526c97f4ac}Material'],
                  readOnly: true
                ),
                a!integerField(
                  value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{7fd4a6cb-f5b7-4f0f-9f86-1680005f8be5}CantidadPdteRecep'],
                  required: true,
                  readOnly: true,
                  validations: {}
                ),
                a!floatingPointField(
                  value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'],
                  required: true,
                  readOnly: true,
                  validations: {}
                ),
                a!integerField(
                  value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum'],
                  saveInto: {
                    fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                  },
                  validations: if(
                    isnull(
                      fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                    ),
                    "",
                    if(
                      fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum'] <= fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'],
                      "",
                      "La cantidad recepcionada debe ser igual o inferior a la cantidad de la línea de pedido"
                    )
                  )
                )
              }
            )
          )
        )
      }
    ),
    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Completar Recepción",
          saveInto: {
            a!save(
              /*cambiar por recordLineasRecepciones*/
              local!DatosLineas2,
              a!forEach(
                local!DatosLineas,
                'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3'(
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{d7518970-ac55-44b5-b525-5a51247887cb}idRecepcion': ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{cb86a21e-a5e5-4ec7-98dc-14e94cc5736c}idRecepcion'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{15ae98c8-aae8-4e42-83ee-cc9f8a15054e}proveedor': ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{e11e6206-fc23-4a4b-9819-4db5a5bab685}nomProveedor'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{0a43fa95-c09b-4b60-9ae5-575d2528608e}createdOn': now() + intervalds(2, 0, 0),
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{c6c28a01-ff0f-4127-b8d5-58afe27e5a4e}createdBy': loggedInUser(),
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{8692352f-94c8-41c3-a9e8-b0e6e4357164}idLineaPedido': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fcfa4b36-4398-4430-8055-ecfa59daf13a}idLineaPedido'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{13436966-037d-4db1-9485-4a63ba64df7f}idPedido': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{4ed86221-1e35-41ab-af39-37897a6e45ca}material': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{69e9a834-b2fb-4f35-a36d-3c526c97f4ac}Material'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{8746ef15-c9ee-4f02-870a-72405fadf88c}precioUnit': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'],
                  'recordType!{9340eead-a0d4-4504-93d9-b117f09a47d2}CPF Lineas Recepciones v3.fields.{403a1827-c369-495b-ba26-f0f31d1d7a59}cantidadRecep': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                )
              )
            ),
            a!save(
              ri!recordLineasRecepV3,
              local!DatosLineas2
            ),
            a!save(
              /*cambiar por recordLineasRecepciones*/
              local!DatosLineas3,
              a!forEach(
                local!DatosLineas,
                'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido'(
                  'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{2da9182e-b3ef-4ef1-abfa-53d4df63d33c}idUnico': fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{2da9182e-b3ef-4ef1-abfa-53d4df63d33c}idUnico'],
                  'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum': if(
                    a!isNullOrEmpty(
                      ri!recordLineasPedido['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                    ) = true,
                    0,
                    ri!recordLineasPedido['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                  ) + fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{bd0fe4ca-322c-422e-89e5-97e5194817a1}CantRecepAcum']
                )
              )
            ),
            a!save(
              ri!recordLineasPedido,
              local!DatosLineas3
            ),
            a!save(
              ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{4f22f1d7-f5cd-446a-90a2-64a5893f912b}idPedido'],
              ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{7309402c-2312-4a4e-bdaa-5654789bffb2}idPedido']
            ),
            a!save(
              ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{cad778de-1c66-4aca-9abf-ebea67e7f4d3}createdOn'],
              now() + intervalds(2, 0, 0)
            ),
            a!save(
              ri!RecordRecepciones['recordType!{b6fc6108-1f5d-4cbe-9c5c-08da4b1d58f3}CPF Maestro Recepciones.fields.{95377c9c-61d7-4677-89bb-3cc3e5150f05}createdBy'],
              loggedInUser()
            )
          },
          submit: true,
          style: "PRIMARY",
          validate: true
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancelar",
          value: true,
          saveInto: ri!cancel2,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  }
)

  Discussion posts and replies are publicly visible

  • In general I'm not sure I would recommend this approach - I think it has the potential to be confusing for end users. In general I would recommend that whatever value is displayed in the grid should become the new value, not be added to the existing value.

    So if you want to do any calculations, I'd recommend adding the calculations within the grid, not within the save. That way, the value displayed in the grid will always exactly match what is in the database.