Create journal entry from pressing custom button

Hello
I am using erpnext v 14.20.3 and i added custom field to oppourtunity this new field is buy value and bid bond amount and i added new custom button called create journal i wanna when user press create journal the system will add a new journal entry any body can help me with this
thanks

Hi @yara,

Please check the syntax.
Then try and check it
Please set your doctype, field name, or table field name according.

frappe.ui.form.on('Your DocType', {
    refresh: function(frm) {
        // Add custom button
        frm.add_custom_button(__('Create Journal'), function() {
            // Create the journal entry using REST API
            frappe.call({
                method: 'frappe.client.insert',
                args: {
                    doc: {
                        doctype: 'Journal Entry',
                        posting_date: frappe.datetime.get_today(),
                        company: frm.doc.company,
                        accounts: [
                            {
                                account: '<your_account>',
                                debit_in_account_currency: frm.doc.buy_value,
                                credit_in_account_currency: 0
                            },
                            {
                                account: '<your_account>',
                                debit_in_account_currency: frm.doc.bid_bond_amount,
                                credit_in_account_currency: 0
                            }
                        ]
                    }
                },
                callback: function(r) {
                    if (r.message && r.message.name) {
                        frappe.msgprint(__('Journal entry {0} created successfully', [r.message.name]));
                    }
                }
            });
        });
    }
});

I hope this helps.
Thank You!

1 Like

Thank you very much