Get_value not working in .js file but working in the browser console

good day all,

I am trying a script to automatically set the value of a field on a form. The value is fetched from a linked field

The script work fine if I put it on the console of my browser.

  refresh: function(frm) {
frm.disable_save();

if (cur_frm.doc.course) {
	frappe.call({
		'method': 'frappe.client.get',
		args: {
			doctype: 'Course',
			name: cur_frm.doc.course
		},
		callback: function(data) {
			cur_frm.set_value('calendar_event_color', data.message.calendar_event_color);
		}
	});
}

Now, I just changed the cur_frm with frm (because frm doesn’t work in the browser console) and the script doesn’t work at all. There is no error message, but the value is not set in the field.

So writing this in my .js file and nothing happen?

  refresh: function(frm) {
frm.disable_save();

if (frm.doc.course) {
	frappe.call({
		'method': 'frappe.client.get',
		args: {
			doctype: 'Course',
			name: frm.doc.course
		},
		callback: function(data) {
			frm.set_value('calendar_event_color', data.message.calendar_event_color);
		}
	});
}

What am I missing or doing wrong?
Thanks for any help you could give.

@f_deryckel you required to refresh the field after setting the value. Try this.

frm.refresh_fields()

1 Like

Hey @abhijit_kumbhar, thanks for the tip. Unfortunately, it doesn’t make any difference. :woozy_face:
I have the frm.refresh_field() both outside the frappe.call and inside the callback() right after the frm.set_value().

if that does not work do you need to write this trigger on refresh only?