How to Track Count for Child Table Row with Script?

I have a Repairing doctype where:

  • Each entry is linked to a specific customer.
  • The child table records all machines serviced on that date, with a serial number field.

Goal: Track how many times a particular machine has been repaired.

  • I added a new field called “repaired count” in the child table.
  • I wrote a script to:
    • Filter records by customer.
    • Sort by date.
    • Check previous entries for the same serial number and update the repair count.

However, the script is not working as expected.

Has anyone implemented a similar logic or faced this issue? Any insights or suggestions would be appreciated!

Solved !