Help needed to convert this custom script to run in V11

We get material from our customers for job work. So we prepare a stock entry which contains details of customer and the items sent. We have a custom script which triggers when we update the field service_material which is a link to “Stock Entry”. The script should update data of customer and items sent to us in quotation so that we may prepare a quotation document.

First half of the code upto the statement $.each…, is working fine but the items child table is not getting updated.

frappe.ui.form.on(“Quotation”, “service_material”, function(frm) {
frappe.model.with_doc(“Stock Entry”, frm.doc.service_material, function() {
var stock_doc = frappe.model.get_doc(“Stock Entry”, frm.doc.service_material);
frm.set_value(“customer”, stock_doc.customer);
frm.set_value(“company”, stock_doc.company);
frm.set_value(“party_gp_no”, stock_doc.party_gp_no);
frm.set_value(“party_gp_date”, stock_doc.party_gp_date);
$.each(stock_doc.item, function(index,row) {
d = frm.add_child(“items”);
d.item_code = row.item_code;
d.item_name = row.item_name;
d.description = row.description;
d.qty=row.qty;
d.rate=row.basic_rate;
d.party_gp_no=stock_doc.party_gp_no;
d.party_gp_date=stock_doc.party_gp_date;
})
cur_frm.refresh_field(“items”);
})
})
frappe.ui.form.on(“Quotation”, “quotation_for”, function(frm) {
frm.set_value(“naming_series”, “FIR-”);
})

Check your other script is also running or not?

I found this strange behavior in V11 where custom script stopped working.
Fixed it via migrating environment to python3 again and resetting production environment.

bench setup socketio
bench build
bench clear-cache

I am still on Python 2.7.6 do you think i should upgrade to Python 3 on a production server.
Thanks

Tried above steps, no change.
Still, master information is being shown but in child table ‘items’ only a blank record is added. Looks like the source records are not being read. Any suggestions would be really appreciated. Thanks.

Still struggling with this. I have also tried

frappe.ui.form.on(“Quotation”, {
service_material: function(frm) {
frappe.model.with_doc(“Stock Entry”, frm.doc.service_material, function() {
var stock_doc = frappe.model.get_doc(“Stock Entry”, frm.doc.service_material);
frm.set_value(“customer”, stock_doc.customer);
frm.set_value(“company”, stock_doc.company);
frm.set_value(“party_gp_no”, stock_doc.party_gp_no);
frm.set_value(“party_gp_date”, stock_doc.party_gp_date);
for(var i in stock_doc.items) {
d = frm.add_child(“items”);
d.item_code = stock_doc.items[i].item_code;
d.item_name = stock_doc.items[i].item_name;
d.description = stock_doc.items[i].description;
d.qty=stock_doc.items[i].qty;
d.rate=stock_doc.items[i].basic_rate;
d.party_gp_no=stock_doc.party_gp_no;
d.party_gp_date=stock_doc.party_gp_date;
}
})
cur_frm.refresh_field(“items”);
frappe.ui.form.on(“Quotation”, “quotation_for”, function(frm) {
frm.set_value(“naming_series”, “FIR-”);
})
}
})

the script is able to transfer the master details, but in child record only a blank entry is added with no details. Can somebody help.
Thanks

remove this part:
cur_frm.refresh_field(“items”);

and try something like this:

frappe.ui.form.on("Quotation","validate", function(frm, cdt, cdn) {

$.each(frm.doc.items || [], function(i, d) {
cur_frm.doc.items[i].project = cur_frm.doc.project;

});


});

Tried this but it did not work, same result. The master data is being added but no items get added. Can you check where i am going wrong. Thanks in advance.

frappe.ui.form.on(“Quotation”, “service_material”, function(frm,cdt,cdn) {
frappe.model.with_doc(“Stock Entry”, frm.doc.service_material, function() {
var stock_doc = frappe.model.get_doc(“Stock Entry”, frm.doc.service_material);
frm.set_value(“customer”, stock_doc.customer);
frm.set_value(“company”, stock_doc.company);
frm.set_value(“party_gp_no”, stock_doc.party_gp_no);
frm.set_value(“party_gp_date”, stock_doc.party_gp_date);
$.each(stock_doc.items || , function(i, d) {
cur_frm.doc.items[i].item_code = stock_doc.item_code;
cur_frm.doc.items[i].item_name = stock_doc.item_name;
cur_frm.doc.items[i].description = stock_doc.description;
cur_frm.doc.items[i].qty = stock_doc.qty;
cur_frm.doc.items[i].basic_rate = stock_doc.basic_rate;
cur_frm.doc.items[i].party_gp_no = stock_doc.party_gp_no;
cur_frm.doc.items[i].party_gp_date = stock_doc.party_gp_date;
})
})
})

I"ve recreated your scenario and the customer and company record does not get populated. In fact, only the custom fields do get populated. I’ve noticed that only the custom fields in the first row are retrieved…even though the item code does not and the item grid appears to be blank.

I’ll keep testing and will let you know if I have any success. Let me know as well if you do come right.
FYI- I had to remove the double quotes to get the script running this far

I have tested your script extensively and found the same result.

This is no doubt quite an alarming issue which only the frappe team can resolve.

I recall the same thing happening some years back with a big name ERP provider from Europe whose name I shalln’t divuldge. Even though they eventually did fix the issue eventually,the effect ever since has resulted in customers being extremely averse to upgrades.

The breaking of custom scripts between v10 and v11 is quite a serious issue that needs attention ASAP.

I can only hope someone from the frappe team will read this post and attend to the issue

The problem may be environment related, so reports may not be consistent and you may need to be creative and persistent. What may help

  • Routinely check the forum for other reports, post # 2 above lists some links

  • For clues review Issues · frappe/erpnext · GitHub

  • Use print statements and run your script in a debugger

  • Redevelop the script to run on v11

Thanks for taking time to try it out for me. I don’t know if it has something to do with python version (i am on version 2.7) or custom script permissions to access or write child table data.
I will keep trying. Thanks again.

I am still stuck on this. Can anybody help. Thanks

Your best option is to create a test environment to run the script in Python 3.6

Do keep me posted if you do come to a solution as I’m also stuck

This worked for me. But it is adding a blank record at the end which needs to be manually deleted. I am this close to nailing it.

frappe.ui.form.on(“Quotation”, “service_material”, function(frm,cdt,cdn) {
frappe.model.with_doc(“Stock Entry”, frm.doc.service_material, function() {
var stock_doc = frappe.model.get_doc(“Stock Entry”, frm.doc.service_material);
frm.set_value(“party_name”, stock_doc.customer);
frm.set_value(“company”, stock_doc.company);
frm.set_value(“party_gp_no”, stock_doc.party_gp_no);
frm.set_value(“party_gp_date”, stock_doc.party_gp_date);
$.each(stock_doc.items || , function(i, d) {
frm.add_child(“items”);
cur_frm.doc.items[i].item_code = d.item_code;
cur_frm.doc.items[i].item_name = d.item_name;
cur_frm.doc.items[i].description = d.description;
cur_frm.doc.items[i].qty = d.qty;
cur_frm.doc.items[i].uom = d.uom;
cur_frm.doc.items[i].rate = d.basic_rate;
cur_frm.doc.items[i].party_gp_no = stock_doc.party_gp_no;
cur_frm.doc.items[i].party_gp_date = stock_doc.party_gp_date;
})
})
})

1 Like

I was about to suggest, to post whatever exception, traceback or message you get.

That helps immensely to identify out what is going on and all here benefit.

@arpanzen- Well done!

@arpanzen Add the line below- before this statement: frm.add_child(“items”);

cur_frm.clear_table(‘items’);

Ok this finally did the trick. Thanks to the developers who must have made it possible to still use custom scripts and to Eli for helping me out in every possible way. With V11.1.33 this script is working perfectly.

frappe.ui.form.on(“Quotation”, “service_material”, function(frm,cdt,cdn) {
frappe.model.with_doc(“Stock Entry”, frm.doc.service_material, function() {
var stock_doc = frappe.model.get_doc(“Stock Entry”, frm.doc.service_material);
frm.set_value(“party_name”, stock_doc.customer);
frm.set_value(“company”, stock_doc.company);
frm.set_value(“party_gp_no”, stock_doc.party_gp_no);
frm.set_value(“party_gp_date”, stock_doc.party_gp_date);
cur_frm.clear_table(“items”);
$.each(stock_doc.items || , function(i, d) {
frm.add_child(“items”);
cur_frm.doc.items[i].item_code = d.item_code;
cur_frm.doc.items[i].item_name = d.item_name;
cur_frm.doc.items[i].description = d.description;
cur_frm.doc.items[i].qty = d.qty;
cur_frm.doc.items[i].uom = d.uom;
cur_frm.doc.items[i].rate = d.basic_rate;
cur_frm.doc.items[i].party_gp_no = stock_doc.party_gp_no;
cur_frm.doc.items[i].party_gp_date = stock_doc.party_gp_date;
})
})
})

1 Like

@arpanzen - Awesome job!