How to update a custom filed in submittable doctype on change of value of another filed?

Tried below method but still I am not able to create table “references” inside “Payment Entry”.

My Server Script.

p = frappe.get_doc({
    "doctype":"Payment Entry",
    "naming_series": "ACC-PAY-.YYYY.-",
    "payment_type": "Receive",
    "party_type": "Customer",
    "posting_date": "2023-12-23",
    "party": doc.customer,
    "paid_amount": doc.custom_advance_paid,
    "received_amount": doc.custom_advance_paid,
    "target_exchange_rate": "0",
    "paid_to": "Cash - AR",
    "mode_of_payment": "Cash",
    "paid_to_account_currency": doc.currency,
})

p.append("references", {
    "reference_doctype": "Sales Invoice",
    "reference_name": doc.name
})
p.insert()
p.submit()