Trigger "New" button is clicked

How can i trigger this button when it clicked, due to i want to ajax call the session warehouse from backend while this buttion is clicked. Your help is highly appreciated.

For those create new sales invoice , i will send request to backend to retrieve the session warehouse, for those old record ,will not send the request to the backend. [how can i implement on this ?]

regards,
Jacob.

You could make the call on the on_load event of the Sales Invoice form, which is triggered on its creation.

@pratu16x7,

I tried onload function, but it onload, which means it will onload for every other submitted record as well…

New record:

Submmited record:

Which is always hit the error of alert box, the code like below:

I want to add a if else statement if the “New” button is clicked… or other method which i can achieve my use case , anyone ?

You could use an if statement in the on_load function that checks to see if a doc name is assigned. That should not be the case for New documents.

Yes as @Ben_Cornwell_Mott suggested, check if frm.doc.__islocal to know if its a new doc or not.

You can also use frm.is_new()

    // add custom button only if form is not new
    if (!frm.is_new()) {
        frm.add_custom_button('Click me', () => console.log('Clicked custom button'))
    }