How to auto-select option depended on previous field?

Hi Team,

How to select any option in Select field from previous selection field.

e.g We have two naming series for Payment Entry, PE & RE.
Is there any option to select particular naming series PE when we select Payment and RE when we select Receive?

Thanks

hi,

look at the example in employee, when you select the salutation it sets the gender.

salutation: function() {
	if(this.frm.doc.salutation) {
		this.frm.set_value("gender", {
			"Mr": "Male",
			"Ms": "Female"
		}[this.frm.doc.salutation]);
	}
},

https://github.com/frappe/erpnext/blob/develop/erpnext/hr/doctype/employee/employee.js

Thanks for your revert, but can I do something using customization. I don’t want to enter in Developer mode.

hi
i was have this situation , i have 3 naming series for payment entry , and i want applying automatically each one for transaction entry (Receive, Pay, Internal Transfer) , so i made this script :

 frappe.ui.form.on("Payment Entry", "payment_type", function(frm) {
  
  if(frm.doc.payment_type == "Receive")
  {
    set_field_options("naming_series", ["ACC-REC-"])
    cur_frm.set_value("naming_series", "ACC-REC-")
  }
  else  if(frm.doc.payment_type == "Pay")
  {
    set_field_options("naming_series", ["ACC-PAY-"])
    cur_frm.set_value("naming_series", "ACC-PAY-")
  }
  else  if(frm.doc.payment_type == "Internal Transfer")
  {
    set_field_options("naming_series", ["ACC-TRA-"])
    cur_frm.set_value("naming_series", "ACC-TRA-")
  }
  });

I hope this will be helpful

2 Likes

Hi @youssef ,

thankyou for the code, I use it as a reference to my case.

Below is the code as reference to other as well :

frappe.ui.form.on("Sales Order", "refresh", function(frm) {
  
  if(frm.doc.order_type == "Samples")
  {
    set_field_options("naming_series", ["SDR-.YYYY.-"]);
    cur_frm.set_value("naming_series", "SDR-.YYYY.-");        
  }
 
  else if(frm.doc.order_type == "Sales")
  {
    set_field_options("naming_series", ["SO-."]);
    cur_frm.set_value("naming_series", "SO-.");        
  }
  
  });

this is to handle a scenario when the record is loaded for the first time render

reference : What event cur_frm.cscript have?

thankyou once again.