Order of Items in BOM Item in BOM DocType [Solved]

Hi Everyone,
Is there any way that we can order the BOM Item list in the BOM Doctype on a custom field.
Like I add one more custom field say serial and I mention 10,20,30,25,40,50,35 for each row respectively.
So the moment I save it, it automatically comes in the order or serial I have mentioned like 10,20,25,30,35,40,50 etc.

Note: I have already try to order the same via customize form for BOM Item, but it didn’t work.

Ruchin Sharma

@ruchin78, do you need reorde it manually changing the value of the idx property in each record.

Both the ways are good for me. If it is possible to change the value of idx will be fine otherwise I will prefer to use a custom field for ordering.

Ruchin Sharma

@ruchin78, do you need change the idx manually! Create a custom routine, do it based in your custom field!

I appreciate if you can elaborate it. I really don’t have an idea, how to do it?

Hi @max_morais_dmm
Its done, I am able to do this via code.
However as of now it is just a basic code to change the idx numbering value.

I am sharing the code by hoping that it will help others too.

frappe.ui.form.on("BOM Item","serial", function(frm, cdt, cdn) { 
var d =locals[cdt][cdn]
var item=frappe.get_doc(cdt,cdn);
frappe.model.set_value(cdt, cdn, "idx", d.serial);

Note: serial is a custom field type Int (Integer).

Ruchin Sharma