Need not mandatory for customized fields while Item group is Services

Hi Friends,
I need not mandatory fields for customize fields ( Image,Color,Category,Stem Size)while item group is “Services” for other item groups it should mandatory of customized fields


frappe.ui.form.on(‘Item’, {
refresh: function (frm) {
// Your custom logic here
},

item_group: function (frm) {
    // Get the value of the "Item Group" field
    var itemGroup = frm.doc.item_group;

    // Check the value of "Item Group" and set the mandatory property accordingly
    if (itemGroup === 'Service') {
        frm.set_df_property('image', 'reqd', 0);  // Make it not mandatory
        frm.set_df_property('category', 'reqd', 0);  // Make it not mandatory
        frm.set_df_property('stem_size', 'reqd', 0);  // Make it not mandatory
        frm.set_df_property('color', 'reqd', 0);  // Make it not mandatory
    } else {
        frm.set_df_property('image', 'reqd', 1);  // Make it mandatory
        frm.set_df_property('category', 'reqd', 1);  // Make it mandatory
        frm.set_df_property('stem_size', 'reqd', 1);  // Make it mandatory
        frm.set_df_property('color', 'reqd', 1);  // Make it mandatory
    }
}

});

I tried this code also but value missing error coming
Thanks in Advance,
Regards,
Sathyaraj

1 Like

Hy @sathya_raj

please check “Service” spelling
Item group and client script spelling are not the same

Thank you

1 Like

First of all, you are doing it not the right way by adding item-specific attributes to the item doctype.

instead, you can try item variants.

Why not try giving a mandatory depends on?
Eval:doc.item_group!=“SERVICES”;