On record event - grid

On “on record event”:
$a = {quantity};
{count_qty} += $a;

This is my grid:
id | art | quantity | carton_nr | count_qty
1 |CS7520A000.10 | 720 | 92P14H7029 | 720
2 |CS7520A000.10 | 12 | 92P15H3022 | 732
3 |CS7520A025.10 | 120 | 92P14H7029 | 852
4 |CS7520A025.10 | 57 | 92P15H3022 | 909
5 |CS7520A050.10 | 120 | 92P14H7029 | 1029
6 |CS7520A050.10 | 63 | 92P15H3022 | 1092

I need to recalculate ?count_qty? on change ?art? name. In example: row (id 3) i have new art and “count_qty” have to start with 120 and not 852.
Is possible?
Thanks in advance

onScriptInit: [article] = ‘’;

onRecord:

if({[article] !== {art})
{
{count_qty} = {quantity};
[article] = {art};
}
else
{
{count_qty} += {quantity};
}

jsb

Thanks jsbinca - it works.