Stock entry Custom script not working

Hi Guys ,

I am actually trying to transfer the manufactured items from one warehouse to the other referring to particular production order , I understand there is some validation where once if the production order gets completed the production_order field for the completed production order will not work in stock entry doc and will also not fetch the item code automatically displaying a message that BOM and manufacturing quantity is required . But in my case till dispatch the item will travel to different warehouse even after the production order gets completed , so while transferring the materials from one warehouse to the other I want to track the items with the production order , for accomplishing this I tried writing a script but it is not working ,

frappe.ui.form.on("Stock Entry", "production_order", function(frm, cdt, cdn){
frappe.after_ajax(function() { 
frappe.call({
       "method": "frappe.client.get_value",
        args: {
		doctype: "Production Order",
		fieldname: "production_item",
		filters: {
		name:["=", production_order]
			 }           			
	      },								
	      callback: function (data) {									
	      console.log(data);
              frappe.model.set_value(cdt, cdn, "item_code", data.message.production_item);

				        }					
	     })

});

});

Any help would really save me .

Thanks

production_order which you used in filiters won’t work. It should be frm.doc.production_order

1 Like

Thanks for the reply @netchampfaris , I used frm.doc.production_order , but still I am getting the same error message that BOM and Manufacturing quantity is required and also it is not fetching the item_code to the stock entry item table .

Please help

args: {
	doctype: "Production Order",
	name: frm.doc.production_order
}

Try this.

1 Like

Thanks a lot for the swift reply @netchampfaris , tried this

but it is not working , I am getting error in the console that

Uncaught Error: BOM and Manufacturing Quantity are required

Please help

Thanks

Guys any help ?

Thanks

Guys I am really struggling with this . Could anyone help me ? The same custom script works everywhere but not in stock entry .

Along with production order you need to mention the BOM as well to get the items.

1 Like

Many thanks for the reply @KanchanChauhan . I tried doing that I am getting Uncaught Error: BOM and Manufacturing Quantity are required error in the console . Tried clicking on get items button , repeatedly getting the same message BOM and Manufacturing Quantity are required. Actually what happens is the qty field in the production order gets converted to fg_completed qty once the production order gets completed . No clue what I should do , any help would really be a life saver .

My problem is with this script in stock entry js file

get_items: function() {
		var me = this;
		if(!this.frm.doc.fg_completed_qty || !this.frm.doc.bom_no)
			frappe.throw(__("BOM and Manufacturing Quantity are required"));

Please help

Thanks

Any help ?