Please Help! Client Side Script

Hi Guys,

I need help… please…

I need a client side script to calculate the Square Meter from Width and Height and then update the price accordingly… I just made some changes to the ‘Quotation item’ doctype and given the enough field for user input. below is the screenshot… please, how can make a script to achieve it… can anyone help me?

1 Like

Hi:

Create a client script like this.
(Note that field names could be different, and some of them seems not exist yet , for instance … Qty .) Field names should not includes blank spaces (per_square_meter is better …)

frappe.ui.form.on('Quotation item', {
	before_save(frm) {

		frm.set_value("Per Square Meter", frm.Width * frm.frm.Height);
		frm.set_value("Total Square Meter", frm.get_value("Per Square Meter") * frm.Qty)

		// Other operations
	}
})

This script will run when Save button were clicked. (“before_save”)

Other way … you can define operations when value change in every field … :

frappe.ui.form.on('Quotation item', {
	Width(frm) {

		frm.set_value("Per Square Meter", frm.Width * frm.frm.Height);
		frm.set_value("Total Square Meter", frm.get_value("Per Square Meter") * frm.Qty)

		// Other operations
	}
})

This is the best strategy, but you will need define functions for each field involved … (Width, Height …)


Maybe this samples doesn’t work as are written exactly.

I am just trying to guide you, i’m not an expert developer.

Hope this helps.

2 Likes

@avc

Thank you so much. really appreciate your reply… let me try this way… I am not a developer but I can check the codes and can create something… if I need any help, hope I can get back to you once again…

1 Like