Hi! I created an editable grid in which the user can add new rows. When the user adds a new row, a number is auto-generated (1 for the first row, 2 for the second one, etc).
My problem here is that, when I run it in the process model, the first time I add a row, a number "2" appears by defect. If I delete the created row and add new ones, then it works in a correct way. What can be happening with this default value? How can I correct it?
1. Error when I first add a row
2. After deleting the row and adding new ones, it works properly
About my code:
1.Configuration of the first column
2. Function used to auto-generate the values (inside the append function)
My code is the following one:
a!localVariables( local!LineasPedido, { a!sectionLayout( label: "Líneas Pedido", labelIcon: "list-alt-solid", contents: { a!gridLayout( label: "A continuación, incorpore las líneas de pedido correspondientes y pulse el botón de creación", headerCells: { a!gridLayoutHeaderCell(label: "Linea Pedido"), a!gridLayoutHeaderCell(label: "Pedido"), a!gridLayoutHeaderCell(label: "Proveedor"), a!gridLayoutHeaderCell(label: "Material"), a!gridLayoutHeaderCell(label: "Precio Unitario"), a!gridLayoutHeaderCell(label: "Cantidad"), a!gridLayoutHeaderCell(label: "Importe Total"), a!gridLayoutHeaderCell() }, 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: "DISTRIBUTE"), a!gridLayoutColumnConfig(width: "ICON") }, rows: a!forEach( items: local!LineasPedido, expression: a!gridRowLayout( contents: { a!textField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fcfa4b36-4398-4430-8055-ecfa59daf13a}idLineaPedido'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fcfa4b36-4398-4430-8055-ecfa59daf13a}idLineaPedido'] } ), a!textField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido'] } ), a!textField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{464f0883-d6d5-4c58-b054-4de8e9e99902}Proveedor'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{464f0883-d6d5-4c58-b054-4de8e9e99902}Proveedor'] } ), a!textField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{69e9a834-b2fb-4f35-a36d-3c526c97f4ac}Material'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{69e9a834-b2fb-4f35-a36d-3c526c97f4ac}Material'] } ), a!floatingPointField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'], a!save( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe'], if( or( isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] ), isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) ), 0, fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] * fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) ) }, required: true, validations: { if( a!isNotNullOrEmpty( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) = false, "", if( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] < 0, "El precio unitario debe ser superior a cero", "" ) ) } ), a!integerField( value: fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'], saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'], a!save( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe'], if( or( isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] ), isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) ), 0, fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] * fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) ) }, required: true, validations: { if( a!isNotNullOrEmpty( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] ) = false, "", if( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] < 1, "La cantidad debe ser superior a cero", "" ) ) } ), a!floatingPointField( value: if( or( isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] ), isnull( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ) ), 0, fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{e78c5b35-026f-4713-8404-05077c6c9152}Cantidad'] * fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{47f4bf32-2e41-4c5a-a7e7-9fc7786bd753}PrecioUnit'] ), saveInto: { fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe'] }, required: true, validations: { if( a!isNotNullOrEmpty( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe'] ) = false, "", if( fv!item['recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{beb59a89-a332-46d3-b718-a8285f58f942}Importe'] < 0, "El importe debe ser superior a cero", "" ) ) }, align: "RIGHT" ), a!richTextDisplayField( value: { a!richTextIcon( icon: "times-circle", link: a!dynamicLink( value: remove(local!LineasPedido, fv!index), saveInto: local!LineasPedido ), linkstyle: "STANDALONE", color: "NEGATIVE" ) } ) } ) ), addrowlink: a!dynamicLink( label: "Añadir nueva Línea de Pedido", saveInto: a!save( target: local!LineasPedido, value: append( local!LineasPedido, 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido'( 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{71427dbb-12db-4f83-bd99-f625bf9af271}idPedido': ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{7309402c-2312-4a4e-bdaa-5654789bffb2}idPedido'], 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{464f0883-d6d5-4c58-b054-4de8e9e99902}Proveedor': ri!record['recordType!{3c95c0e4-e69d-43f6-b485-e72b24252af7}CPF Maestro Pedidos.fields.{e11e6206-fc23-4a4b-9819-4db5a5bab685}nomProveedor'], 'recordType!{495578a9-1b23-4253-8145-6418faabe727}CPF Lineas Pedido.fields.{fcfa4b36-4398-4430-8055-ecfa59daf13a}idLineaPedido': count(local!LineasPedido) + 1 ) ) ) ) ) } ), a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Completar Creación Pedido", saveInto: a!save( ri!recordLineasPedido, local!LineasPedido ), submit: true, style: "PRIMARY", validate: true ) }, secondaryButtons: { a!buttonWidget( label: "Cancelar", value: true, saveInto: ri!cancel2, submit: true, style: "NORMAL", validate: false ) } ) } )
Thanks a lot!
Discussion posts and replies are publicly visible
That's simple. count() includes NULL values. In the initial state, your local variable in line 2 holds a single NULL value. I suggest to initialise it using "{}". This makes it an empty list. Then count({}) equals zero.
Thanks Stefan! I have changed the expression to count({}) but it´s happening the same
Sure. That is because now, you put a NULL value into a list and try to count the items in that list. That will again evaluate to "1" in case the local variable is NULL.
I repeat my suggestion: "I suggest to initialise it using "{}"."
You need to do that in line 2 of your code in the initial post.
Thanks a lot Stefan! You were right, just by initializing the local variable in the line two the error disappears. Now it works properly