What event runs only once after a "Make" button?

Hi I hope someone can help me with this:

I want to write a function in a custom script that will look for a variable in javascript which I set which is a throw away something like this:

frappe.ui.form.on("Purchase Invoice", "onload_post_render", function(frm) {
        cur_frm.set_query("return_against", function() {
            // if (cur_frm.doc.letter_head == null) return;
            return {
                query: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_debit_note_query",
                   filters: {"pr_number": cur_frm.doc.my_var}

So I want it to only run once after “Make > Debit Note”. When I tie it to “onload_post_render” it will look for it everytime even when I try to save it later and complain that cur_frm.doc.my_var is not found. Is there such an event which I need ?

Don’t make “Return Against” field editable and change the value. There are some other hidden fields which are set on “Make Debit Note” event. If you manually change Return Against value, those field will not change and will create problem.

But if you want to do something else after the “Make Debit Note” event, you can write that function in onload_post_render and adding a if(frm.doc.__islocal && frm.doc.return_against) condition. This will make sure that the event will call only once in case of debit note.