Custom Script: add_fetch doesn't work with if statement

Hello,

So, I have a custom script the populates stock entry ‘default source warehouse’ and ‘default target warehouse’ from a linked field inside Employee

when using the add_fetch method from outside the if statement it works like a charm but when using it inside IF statement it doesn’t work although the print message method within the same condition works fine.

Here’s my code:

frappe.ui.form.on('Stock Entry',{
	stock_entry_type : function(frm) {
		//cur_frm.add_fetch('employee_id',  'default_warehouse',  'from_warehouse');
		
        if (frm.doc.purpose == 'Material Transfer') {
		     // refresh_field("purpose");
		     msgprint('Message 1');
		     cur_frm.add_fetch('employee_id',  'default_warehouse',  'from_warehouse');

        } 
		
	}
})

Please try this.

if (frm.doc.stock_entry_type == 'Material Transfer') {

doesn’t work either, it should work even with it set as purpose because the print function when that condition is met works fine while the fetch command just the line after print doesn’t work even when the condition is met