Skip to main content
natashan0002
February 9, 2023
Solved

Update field of record type using foreach to update serial number

  • February 9, 2023
  • 8 replies
  • 1 view

Hello,

I have a record type with n number of values. The serial number is also saved.

For eg, there is an editable grid. with the serial number as 1,2,3,4. Now i can delete any row and hence the serial number should get updated.  

How to do this in saveinto of that delete button?

I tried using foreach, but im doing some syntax error. Can you tell me any alternative?

    Best answer by natashan0002

    This worked:

    a!save(ri!record['recordtype!record.maintenanceScheduleTypeId'], (enumerate(count(ri!record))+1)                                     )

    8 replies

    stefanhelzle0001
    Brainy
    February 9, 2023

    We trade tips for details in this community. Do you have anything to offer? Error messages? Code snippets?

    natashan0002
    February 9, 2023

    harshitb6843
    February 9, 2023

    If the serial numbers are not sitting in the DB, then simply use fv!index instead of the serial numbers. 

    And if it does sit in the DB, then you will have to update all the rows that come after the one you deleted. For this, you will have to use a loop. 
    Adding a sample code snippet below...

    natashan0002
    February 9, 2023

    Yes i need the looping. Can you share the snippet?

    harshitb6843
    February 9, 2023

    Something like this

    a!localVariables(
      local!outerIndex: fv!index,
      a!forEach(
        items: enumerate(count(local!data)-fv!index),
        expression: a!update(
          data: local!data[fv!index],
          index: "serialNumber",
          value: local!outerIndex+fv!item
        )
      )
    )

    natashan0002
    natashan0002AuthorAnswer
    February 9, 2023

    This worked:

    a!save(ri!record['recordtype!record.maintenanceScheduleTypeId'], (enumerate(count(ri!record))+1)                                     )