Custom script not work for quick entry

I want to run code on quick entry save button…but no code work on quick entry…

1 Like

Can you please upload the script or any screenshot related to that. Which will be helpful.

i want to run my code when we create new customer using quick entry…below code works when we create new customer normally…but not work with quick entry

function removeSpecialChars(str) {
return str.replace(/[^A-Z0-9]+/ig, “”)
}

frappe.ui.form.on(“Customer”, “validate”, function(frm, cdt, cdn) {
frm.doc.ic_number=removeSpecialChars(frm.doc.ic_number)
console.log(frm)
refresh_field(“ic_number”)
})

also try

https://github.com/frappe/frappe/pull/3817

solved using hooks…hooks will work

hello @pratikcws can you please share complete solution?

1 Like

2 ways to do it first using hook and second one is overwrite quick entry.

for overwrite quick entry use this here you can do all code as you want

var dialog = new frappe.ui.Dialog({
				title: __("New Property Handover Defect Category"),
				fields: [
				{
					fieldtype: "Link",
					fieldname: "project_name",
					label: __("project"),
					options: "Project",
					reqd: 1,
					onchange: function(e) {
						console.log(this.value) 
						console.log(dialog)
						if(this.value){
							options = [];
							
							cur_dialog.refresh()
						frappe.call({
						method: 'property_handover.property_handover.doctype.property_handover_defect_category.property_handover_defect_category.project_builing_qty',
						freeze: true,
						args: {
								parent: this.value
							},
						callback: function(data){ 
								(data.message || []).forEach(function(row){   // start a loop over all options in the response, or in a empty list;
									   options.push(row.building_name) // makes a option entry 'value' and 'label'
									 });
									 console.log(options)
									 // dialog.fields_dict.building_name=options;
									 cur_dialog.fields[1].options=options
									cur_dialog.refresh()
							}
						})
					}
					}
				},
				{ fieldtype: "Select",
						fieldname: "building_name",
						label: __("Building Name"),
						options: "",
						reqd: 1,
					},
				{ fieldtype: "Data",
						fieldname: "category_name",
						label: __("Area/Location (Category)"),
						reqd: 1,
					}
				
				]
		})
		dialog.set_primary_action(__('Save'), function() {
			if(dialog.working) {
				return;
			}
			var data = dialog.get_values();
			console.log(data)
			if(data) {
				
				dialog.set_message(__('Saving...'));
				insert(dialog)
			}
		});
dialog.show()

USING HOOKS:

for example you want to create quick entry for customer doctype : (create new customer)

add this hook in parent doctype : for example you are in delivery doctype and here you have customer link type in which you want to use quick entry…

go to delivery doctype hooks and add below hook with your method

"Customer": {
 		"validate": "erpnext.selling.doctype.customer.customer.quickentry"
	},

now go to method and add this code

@frappe.whitelist()
def quickentry(self,method):
	ic=re.sub('[^A-Za-z0-9]+', '', self.ic_number)
	self.db_set('ic_number', ic)
	if self.mobile_no:
		number=re.sub('[^0-9+-]+', '', self.mobile_no)
	self.db_set('mobile_no', number)

if you still face issue give me your scenario.

1 Like

check this code if still face any issue feel free to ask

actually i’ve just one field in quick entry, which is Link type, and i want to override its query, i’ve already done in form, but its not working in quick entry, what is easiest way to achieve this? overriding or hooks? i think hooks will not work for this, and don’t know if overriding works for this.

1 Like

for link field we always use overwrite method because there is no other way to filter link field …if you need any help i will

can you show me example please?

add this in your doctype and add all fields i.e. shown in your dialog
var dialog = new frappe.ui.Dialog({
title: __(“New Property Handover Defect Category”),
fields: [
{
fieldtype: “Link”,
fieldname: “project_name”,
label: __(“project”),
options: “Project”,
reqd: 1,
onchange: function(e) {
console.log(this.value)
console.log(dialog)
if(this.value){
options = [];

						cur_dialog.refresh()
					frappe.call({
					method: 'property_handover.property_handover.doctype.property_handover_defect_category.property_handover_defect_category.project_builing_qty',
					freeze: true,
					args: {
							parent: this.value
						},
					callback: function(data){ 
							(data.message || []).forEach(function(row){   // start a loop over all options in the response, or in a empty list;
								   options.push(row.building_name) // makes a option entry 'value' and 'label'
								 });
								 console.log(options)
								 // dialog.fields_dict.building_name=options;
								 cur_dialog.fields[1].options=options
								cur_dialog.refresh()
						}
					})
				}
				}
			},
			{ fieldtype: "Select",
					fieldname: "building_name",
					label: __("Building Name"),
					options: "",
					reqd: 1,
				},
			{ fieldtype: "Data",
					fieldname: "category_name",
					label: __("Area/Location (Category)"),
					reqd: 1,
				}
			
			]
	})
	dialog.set_primary_action(__('Save'), function() {
		if(dialog.working) {
			return;
		}
		var data = dialog.get_values();
		console.log(data)
		if(data) {
			
			dialog.set_message(__('Saving...'));
			insert(dialog)
		}
	});

dialog.show()

1 Like

Thanks, let me try.

is your problem solved??

Sorry @pratikcws haven’t checked it yet, will share result here after checking.