How to edit New Item Dialog

Hello
I want to edit custom field from custom script but i don’t know how to do
Please suggest me if anyone know how edit

Do you wish to add your custom field to the New Item Dialog ?

See if making it mandatory does the trick ?

actually i want to add custom script code according some conditions i want to hide item code field

Okay tell me if i am right. You want to hide a field in Item, based on some conditions by using a custom script ?

yeah i want it

okay explain what field do you want to hide and what conditions do you wish to check ? It is possible it is simple enough to be handled just via Customize Form and there is no need for a custom JS

if any logged in user have Role checked in user list “Sales Prospector” then item code should be hide

actually Edit in full page i am able to do this requirement but in dialog box i am not able to do

you can check via this JS statement:

if (frappe.user.has_role('Sales Prospector'))

Actually if you are going to create a new item then you need item code. Also that field is mandatory.

Do users having role ‘Sales Prospectors’ need to create items ?

actually i am doing for that user naming series instead of item code i am taking naming series that’s why i want to hide that field

all things i can do but only i want to know how to apply custom script code for that dialog box

Thanks

Okay do one thing. Write your JS for the like this :

frappe.ui.form.on("Item", {
	quick_entry: function(frm) {
		//write your code here
    }
})

But again I will bring to your notice in case you actually want to hide Item Code field, If you are creating a new Item (hence accessing the Quick Entry mode), you will need the Item Code field. Also, it is a mandatory field and going around that validation is a bit difficult.

Yeah

internally i am creating naming series for item code so no need to worry about that

1 Like

not working for dialog box
how i am using your code
frappe.ui.form.on(“Item”, {
quick_entry: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var item_code = d.item_code;
console.log(“item_code----------”+item_code);
}
})

What is the output of logging “d”?

okay that dialog box can be manipulated if you use cur_dialog.

Also no need of cdt and cdn, there is no child doctype in the quick entry.

Sorry for late reply

how to use cur_dialog can you please give me some reference

Just like you use cur_frm. Try using it in a similar fashion

see i am using code like this

frappe.ui.form.on(“Item”, {
quick_entry: function(frm) {
var user = frappe.session.user;
if (frm.doc.__islocal) {
var user_dtails = user_function(user);
if (user_dtails == “Sales Prospector”) {
dialog.fields_dict.item_code.$wrapper.hide();

}
}
}
});

Is quick_entry a valid event name? @root13F

The new item dialog is custom code. Here’s an example of an override I did to add default warehouse. I have truncated some fields in the middle, don’t expect to be able to copy/paste. Because Item uses a custom Quick Entry dialog, you won’t be able to use Customize Form to add or remove fields, and many of the ones you’d want are in child tables anyway.

frappe.provide('frappe.ui.form');

frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
	init: function(doctype, after_insert) {
		this._super(doctype, after_insert);
	},

  render_dialog: function() {
    this.mandatory = this.get_fields()
    this._super();
    this.dialog.$wrapper.find('.edit-full').text(__('Edit in full page to set additional UOMs, Asset or other details'))
  },
  get_fields: function() {
		return [
		{
			label: __("Item Code"),
			fieldname: "item_code",
			fieldtype: "Data"
		},
		// more fields here
        {
			label: __("Default Warehouse"),
			fieldname: "warehouse",
			fieldtype: "Link",
			options: "Warehouse"
		}
     ]
  },
  register_primary_action: function() {
		var me = this;
		this.dialog.set_primary_action(__('Save'), function() {
			if (me.dialog.working) return;

			var data = me.dialog.get_values();
			if (data) {
        me.doc.disabled = 1
        me.dialog.doc.item_defaults = []
        me.dialog.doc.item_defaults.unshift( {
          company: frappe.defaults.get_user_default('company'),
          default_supplier: data.supplier,
          buying_cost_center: data.subsystem,
          default_warehouse: data.warehouse
        })
        me.dialog.doc.supplier_items = []
        me.dialog.doc.supplier_items.unshift({
          supplier: data.supplier,
          preferred_supplier: 1
        })
        // console.log(me.dialog, data)
				var values = me.update_doc();
			}
      me.insert();
		});
	},
})

1 Like