How to create a Payment Entry using button


I want to create a payment entry using the client script, the following code

frm.add_custom_button("Caret Payment Entry", function(){
	// create Payment Entry when click Check In button
		'doctype': 'Payment Entry',
		'payment_type': "Receive",
		'party_type': "Customer",
		'party': frm.doc.customer,
		'paid_amount': frm.doc.rounded_total,
		'received_amount': frm.doc.rounded_total,
		'source_exchange_rate': frm.doc.conversion_rate,
		'target_exchange_rate': frm.doc.conversion_rate,
		'references': [{
			'reference_doctype': frm.doc.doctype,
			'reference_name' :
	}).then(doc => {
		frappe.show_alert("Payment Entry is created successfully")

I use this button in sales orders to create a payment Entry directly, but every time I run the code I face an Error for missing another field

what is the stander column used in Payment Entry to create it?


@Omar_Mohammed can you share / post errors you are facing ?

this is an error message,
each time it tells me need to another field

There are few fields needs to be filled,

Please also include this fields into your code with values (mode_of_payment,paid_to,paid_to_account_currency)

Paid to is the account in which amount will be received, paid_to_account_currency is currency of that account

1 Like

Thank you Hardik, I solve it with your solution, @Hardik_Gadesha

but the child table (references) is not created, is there any mistake while inserting the child table (references)

'references': [{
	'reference_doctype': frm.doc.doctype,
	'reference_name' :

I also had problems with references table being created while posting Payment Entry using script. I doubted it is probably mismatch in the outstanding amount in the invoice, i dint fix it later.

I used append function for adding to child table. Your issue might be solved with append function.

append function is working with py files, and I use client script js

I have another task, is How do I fetch the paid_to account automatically?? is it from the Sales Invoice, or where?

now I use static solution
paid_to = 1110 - Cash - TG