Good day lovely community,

I'd like to implement the following functionality for CRM 2016 8.2:

A Button labelled "create delivery note" in sales orders, which opens a small window and lets you not only select the items of the current sales order but also input the amount which is to be delivered. Confirming the selection a new delivery note record with its very own delivery note products will be created. Now this much I managed to do with httprequests, Datatables and REST API on client-side. Something I'd like to accomplish is somehow keep track on the items and their amount which have been already delivered. E.g:

Sales Order 1:

Product A with quantity 2

Product B with quantity 1

when clicking on the button and selecting A and B as follows: A quantity 1 and B quantity 1, it should produce a new record with both of these items. Now when clicking on the create delivery note button again it should only display Product A with a maximum of 1

How could I achieve and implement this?
I am grateful for every bit of advice the community could give me

Sincerely
Max