RE: How to generate a batch number using batch job x++
SalesLine has InventDimId field, which is reference to InventDim table. And InventDim table has InventBatchId field, which is the value you see in the form.
Values of InventBatchId field comes from InventBatch table. It's not clear if you want to use an existing value or create a new record in InventBatch table and use the newly created batch ID in InventDim. Please clarify.
When working with InventDim table, set values (e.g. InventBatchId) and then call findOrCreate() method to eirher find existing record for the given combination, or to create a new one (with a new unique InventDimId). Then use this InventDimId in SalesLine.
For example:
InventDim inventDim = salesLine.inventDim(); // Current dimensions from SalesLine
inventDim.InventBatchId = ...
// Don't call update() on InventDim
salesLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;