Fetch purchase order record through client script

I want to view purchase order list in sales order doctype through client script then how do I add it through custom button

@Runway I dunno why u want to achieve it through client script since the Sales Order dashboard already has the connection such as below:

If u still insist to do the client script u can try the following, I haven’t tested it though

frappe.ui.form.on('Sales Order', {
	refresh(frm) {
		frm.add_custom_button(__("Testing"), function() {
        	frappe.call({
        		method: "frappe.client.get_list",
        		args: {
        			doctype: "Purchase Order Item",
        			filters: [
        				["sales_order", "=", frm.doc.name]
        			],
        			fields: ["parent"],
        			parent: "Purchase Order"
        		},
        		callback: function(r) {
        			if (r.message) {
        				console.log(r.message);
        			}
        		}
        	});
        });
	}
})

I don’t want to add the connection like this, I want to add a new purchase order button in the get item in the sales order and show the list of purchase orders from the list of purchase orders as it appears in the quotation and from the list of purchase orders. How do I add the desired purchase order to the item table of the sales order?

I want to add in sales order in this way purchase order button i added also item is shown there i can also select it but when i add it i get error

Error come like this:

How to solve that error

U getting the error once u click on Get Items is it? If so, could u show the code inside Get Items. And also could u copy paster full traceback from the console.

Console Error

Could u replace me.frm > frm and also could u add the setters dict into a array?

I can replace me.frm > frm but it’s not work and i not tried to add the setters dict into array how can i add the setters dict into a array please tell me about how to add the setters dict into a array.

erpnext.utils.map_current_doc({
	method: 'erpnext.buying.doctype.purchase_order.purchase_order.make_inter_company_sales_order',
	source_doctype: 'Purchase Order',
	target: frm,
	setters: [
		{
			label: 'Supplier',
			fieldname: 'supplier',
			fieldtype: 'Link',
			options: 'Supplier',
			default: frm.doc.supplier || undefined
		}
	],
	add_filters_group: 0,
	child_fieldname: "items",
	child_columns: ["item_name"]
})

Hello i tried to use this but come error: No Customer found for Inter Company Transactions which represents company company-name

Hello any solution able to this question.

When u use make_inter_company_sales_order, do u understand what is it for? The error showing is because of a validation, following are the codes. If could not find the parties, it will throw a error. So there should be customer that fulfill the filters.
image

It not worked.

As per my above requirement if I want to get purchase order list which should be opened by custom button added in client script in sales order then what should I do for it?

U can refer to this 2 files, basically it try to make Sales Order based on Quotation. This is the correct way for u to achieve it.
https://github.com/frappe/erpnext/blob/b98d25dafb6e3dc2c289048911e68641d2ba15e7/erpnext/selling/doctype/sales_order/sales_order.js#L276
https://github.com/frappe/erpnext/blob/4ad3002861339651e85ac9ab4e532251b03590b2/erpnext/selling/doctype/quotation/quotation.py#L197

This way is correct but you can help me on which place in change for get purchase order list in sales order doctype