Updating Last 2 rows of another DocType Child

I have a doctype named assign_item with field named item_code and this doctype is submittable
and another doctype named hw_item with field named item_code and this doctype has inside a child table called item_usage and this doctype is not submittable.

I want when submit assign_item doc , to update last record in item_usage child table of the hw_item with the same item_code and also to add a new record in the item_usage table.

I prefer to use client side script for this task,

can someone help me with the code?