Set value of a field based on other field's value

How to set value for a field based on other field’s value?
E.g. I’m using multi-company setup, so based on the company field value, it also changes value of naming series…

I tried to insert these codes under Custom Script…but it didn’t work…

frappe.ui.form.on("Delivery Note", "company", function(frm) {
doc.naming_series = "";
switch(doc.company) {
case "ABC":
doc.naming_series = "TPM-DN-.####";
break;
case "DEF":
doc.naming_series = "DN-.####";
break;
default:
doc.naming_series = ""
}
});

Any hints?

@jof2jc : Have a look through this thread : Trigger recalculation after change in customfield

Hi All,

Trust everyone’s doing great. I’ve been trying to figure out the exact same thing!

I would greatly appreciate it if the format (or better still an example) for achieving this could be suggested. The link posted by @Eli didn’t exactly answer this question… at least not for the non-devs :slight_smile:

Many thanks!

Still hoping for some assistance here :slight_smile:

Honestly, I think this should be a standard feature in ERPNext. There are several use cases for this. As already mentioned, it is helpful when we need to set a naming series of a doc based on the value in the company field for example. Or it could be used to automatically select the appropriate series (i.e. SINV-RET-) based on the value of the ‘Is return’ field

In the meantime, if you could just provide a custom script sample which can be edited to suit the particular use case, that’ll be just great

Many thanks

Interested on this as well as running the same setup multi-site business, so would be ideal if this was automated or a custom script would be fine as well…

hope someone can help with this.

thanks

+1 Agree for this to be standard part of erpnext customizations for all form fields!
Benefits -

  1. It can help automate a lot of entries and improve the user experience, (by avoiding repetitive feeding)
  2. Can decrease chances of error in manual feeding.
  3. Possibly hide the (auto feeded) fields, thereby simplifying the overall form for user on the floor.

@LifeP @wale

Please create Github Issue for this feature suggestion.

Thanks @umair

Done!