Problem 1 - Limiting Item Code Length
For my setup the Item Code is created from individual fields .{custom_product_line}.-.{custom_product_class}.-.{custom_pn_value_1}.-.{custom_region_selected}.-.{custom_language_selected}.-.##.
I would like to limit this to 28 characters, which I tried using the Length option in Form Builder but this did not work.
I presume because it’s evaluating the naming series option first, which is 131 characters and the over the limit, rather than the sum of the actual field contents which is a lot less.
Is there another way to do this?
Problem 2 - Make Item Code Uppercase and Strip Spaces
I have tried the code from this post but it didn’t work for me
My code
if doc.item_code:
doc.item_code = doc.item_code.upper()
doc.item_code = doc.item_code.strip()
Not sure why but even using one option at a time doesn’t work.
Are there any other ways or have I made a mistake somewhere?
Ok, still not sure about the length issue but here is another approach which seems to be working for the making the entry uppercase and removing spaces.
Instead of applying this to the item_code field, instead I’ve applied the following Client Script to the input fields (custom_pn_value_1 and custom_pn_value_2) to make the entry uppercase and remove spaces at the point of data entry:
frappe.ui.form.on("Item", {
custom_pn_value_1: function(frm) {
if (frm.doc.custom_pn_value_1) {
// Convert the value to uppercase
frm.set_value("custom_pn_value_1", frm.doc.custom_pn_value_1.replace(/\s+/g, "").toUpperCase());
}
},
custom_pn_value_2: function(frm) {
if (frm.doc.custom_pn_value_2) {
// Convert the value to uppercase
frm.set_value("custom_pn_value_2", frm.doc.custom_pn_value_2.replace(/\s+/g, "").toUpperCase());
}
}
});