Im having trouble with a custom scrip used to both select the naming series based on the company and validate the naming series based on the company. I can get both part of the scripts to work independently but not together. when I combine both parts of the script I am unable to save.
I want the validate even tough it auto selects based on the company to ensure the user didn’t change the naming series manually before saving. I am still learning scripting so any help is greatly appreciated!
cur_frm.cscript.onload_post_render = function(doc,cdt,cdn){
if(cur_frm.doc.company == "Cinema Hardware LLC"){
cur_frm.set_value("naming_series","INV-.#####");
}
if(cur_frm.doc.company == "Cinema Hardware GmbH"){
cur_frm.set_value("naming_series","RG-.#####");
}
};
frappe.ui.form.on("Sales Invoice", "validate", function(frm) {
if (doc.company == "Cinema Hardware LLC") {
if (frm.doc.naming_series != "INV-.#####"){
msgprint("Please select correct naming series for company");
Validate = false;
}
}
if (frm.doc.company == "Cinema Hardware GmbH") {
if (frm.doc.naming_series != "RG-.#####"){
msgprint("Please select correct naming series for company");
Validate = false;
}
}
});