Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

Frappe msgprint Error

Hi everyone i’m trying to print a message using frappe.msgprint when an item is out of stock which will be associated with a link to item with insufficient stock .
The message is generated but the problem is the link is not replaced by the item code value.
Image of the message

Here is the msgprint code on the client side

frappe.msgprint(__('Print Failure Insufficient Stock for Item:<a href="/desk#Form/Item/{0}">{0}</a> ', [frm.doc.sal_flagged_item]));

Any help would be much appreciated, Thank you.

This is because the field sal_flagged_item was not found, it is either spelt incorrectly or not referenced properly. Keep in mind that you cannot access this field directly if it belongs to a child table.

Thanks for the reply @walstanb i have been doing further tracing the field is spelt correctly but for some reason it’s value is undefined which means the value was not set but i can’t figure out why it’s that way because the function to set the value is called on refresh
here is the full js

frappe.ui.form.on('Pick List', {
	refresh: function(frm){
		console.log(frm);
		
		//Code for custom cancel button that saves cancel reason first
		if(frm.doc.docstatus == 1){
			frm.page.clear_secondary_action();
			frm.page.set_secondary_action(__("Cancel"), function(frm) {
				cur_frm.events.before_cancel_event();
			});
		}
		
		if(frm.doc.docstatus == 0 && frm.doc.__islocal == 1){
			frm.set_value('print_date_time', '');
			frm.set_value('track_print_user', '');
			frm.set_value('pl_text', '');
			//frm.set_value('sal_flagged_item', '');

		}

		dashboard_pick_list_doctype(frm, "Sales Order");
		get_undelivered_pick_list(frm);

	},
	
	on_submit: function(frm){
		if (frm.doc.sal_flag_qty != 1) {
			
			var new_url = window.location.origin + "/printview?doctype=Pick%20List&name=" + frm.doc.name + "&trigger_print=1&format=Pick%20List%204*6&no_letterhead=0&_lang=en"		
			window.open(new_url)
		}				
		else{
			frappe.msgprint(__('Print Failure Insufficient Stock for Item:<a href="/desk#Form/Item/{0}">{0}</a> ', [frm.doc.sal_flagged_item]));
			console.log("Working:" + frm.doc.sal_flagged_item)
		}
		
	},
	
	before_cancel_event: function(frm){
		frappe.prompt([
			{'fieldname': 'cancel_reason', 'fieldtype': 'Small Text', 'label': 'Enter Reason', 'reqd': 1}
		],
		function(values){
			frappe.call({
				'method': 'metactical.custom_scripts.pick_list.pick_list.save_cancel_reason',
				'args': {
					'docname': cur_frm.docname,
					'cancel_reason': values.cancel_reason
				},
				'callback': function(r){
					cur_frm.savecancel();
				}
			});
		},
		'Please reason for cancellation.',
		'Cancel'
		)
	},
});

var get_undelivered_pick_list = function (frm) {
	
	var count = 0;
	var locations = frm.doc.locations;
	
	locations.forEach(function(row){
		frappe.call({
			'method': 'metactical.custom_scripts.pick_list.pick_list.get_undelivered_pick_list',
			'args': {
				'item_code': row.item_code,
				'warehouse': row.warehouse,
			},
			'callback': function(r){
				var items = [];
				$.each((r.message), function(i, d){
					items.push(d);		
				})
				set_qoh_flag(frm, items);
			}
		});
	});

}

// set qoh
var set_qoh_flag = function(frm, items){
	
	var undelivered_pick_list = [];
	
	items.forEach(function(row){
		console.log(row);	
		if ((row.actual_qty - row.reserved_qty) < 0){
			frm.doc.sal_flag_qty = 1;
			//frappe.model.set_value('sal_flagged_item', row.item_code)
			frm.doc.sal_flagged_item = row.item_code;
		}	
	
	});
	console.log(frm.doc.sal_flagged_item);
	console.log(frm.doc.sal_flag_qty);

}

The correct field name was sal__flagged_item just missed it, Thank you very much

1 Like