Good morning I have just successfully done the same thing you are describing.
At a high level
Work Order Record Transform into Assembly Build
Select Line "Component"
Get the lot info record with: getCurrentSublistSubrecord component, componentinventorydetail
For each linecount in lot info record
select line at index
setCurrentSublistValue inventoryassignment, quantity
commitLine inventoryassignment
When I transform a Work Order into an Assembly Build, I chose to use Dynamic Mode which I assume you are too because I see "commit line" used in your post. When iterating through the lot lines of a component, you will notice that NetSuite automatically populates them with info just like it does in the GUI.
In my implementation, I did not use "select new line" but instead used selectLine with a line number of the current index of the loop. Each time you visit a lot, either set it's quantity and commit the line, or remove that lot line. You will also need to keep track of the index carefully because all lots will shift "up" in index when a lot above is removed.
I suggest to keep track of lot numbers to keep, and then use a separate function to loop the lots and remove any not marked for keeping
Another thing to be careful of is that you read the 'quantityavailable' field on the lot, to get unpicked quantity.
What is the full error you are receiving? Can you post the entire function?