Not able to save changed value in child table

Hi Everyone,
Below is my code by which I am able to do some calculation and updating
Item Code
Item Name and
Description in child table but the issue is the moment the document get submitted it returns to old value.
I appreciate if anyone can let me know, what did I miss in it.

frappe.ui.form.on("Sales Order", "before_submit", function(frm){

for (var i in frm.doc.items)
	var d1 =  { "item_code":  frm.doc.items[i].item_code
                method: "library_management.item_script.generate_custom_codes",
                args: d1,
	callback: function(r) { 

		$.each(cur_frm.doc.items || [], function(i,item) {
			if(item.item_code == r.message.passed_code)
				item.custom_code_ref = r.message.item_code
				item.item_code = r.message.item_code
				item.item_name = r.message.item_name
				item.description = r.message.description

Ruchin Sharma