What could cause this to only trigger on second selection onwards?

Hi Everyone,

I have encountered a really strange occurance and couldn’t understand what could cause this.

Basically I wanted to fetch some data and populate a few other data fields when user selects a customer on the link fields.

Below is the code:

customer: function(frm,cdt,cdn) {
console.log (“Test”);
cur_frm.add_fetch(‘customer’, ‘customer_address’, ‘customer_location’);
cur_frm.add_fetch(‘customer’, ‘contact_person_name’, ‘contact_person_name’);
cur_frm.add_fetch(‘customer’, ‘company_phone_number’, ‘company_phone_number’);
cur_frm.add_fetch(‘customer’, ‘customer_email’, ‘customer_email_address’);
cur_frm.add_fetch(‘customer’, ‘customer_phone_number’, ‘contact_person_phone_’);

var me = this;
erpnext.utils.get_party_details(this.frm, null, null,
function(){ me.apply_pricing_rule() });


The end result is:
Each time form is loaded, the first time the user selects a customer , nothing would happen.
But I can see the word “TEST” occur on console.

Only when the user selects the customers a second time, the data would get populated and a second “TEST” would occur on console.

Since the first time the user selected a customer on the link field, the “TEST” word occured, It means that the functions was executed, but strangely the add_fetch block was not executed.

Only when the user selects the customers a second time the Add_fetch block would execute, any subsequent changes on the link field after that will also run normally.
Which is strange isn’t it?

Can anyone explain how/why this can happen? How do I ensure the Add_Fetch block is executed on the first attempt?

No one have a clue?

you dont need to write script to fetch customer data.

for these customer fields go to option and write like.



and other functions you can call in this event.

Lol, thanks, this worked !!

Wished I knew what sort of entries can be put into the options field of a forms better …