How to show only those items that are in Sales Order?

Hello,

I have create a DocType in which a user has to select Sales Order and then only they can see Items. Here only those Items which are in Sales Order should be visible in the list.

I have defined the field of Type Link and am linking it to Items.

How can we do this with custom script?

TIA

Yogi Yang

Hello,

I managed to solve my problem putting following code in my DocType.

Code in file my_work_order.js

sales_order:function(frm){
        //Code to get Selected Items Qty to Mfg
        let so_num = frm.doc.sales_order;
        if(so_num){
            frm.set_value({
				"production_item": ""
			});
            
            frappe.call({
                method: "mymfg.api.get_items_from_sales_order",
                args: {sales_order_name: so_num}
            }).done((r) => {
                frm.set_query('production_item', function(){
                    return {
                        filters: [
                            ["Item","name", "in", r.message]
                        ]
                    };
                })
            })
        }
    }

Code in file api.py

@frappe.whitelist()
def get_items_from_sales_order(sales_order_name):
	out = frappe.db.sql_list(
		"""
		select item_code from `tabSales Order Item` where parent = %s
	""",
		(sales_order_name),
	)

	return out

I hope this will help others.

TIA

Yogi Yang