Auto populate field value


Is there any script or codes which can automatically assign the lead owner.
E.g, if I select lead source or any dropdown value of a field as Outdoor, it should automatically set the lead owner as a specific User.

Any help shall be highly appreciated.

share screenshot

Thanks Omar for your quick response.

Below is the screenshot.

If i select Under Construction office, it should automatically select a particular user.

Appreciate your support.


There are many ways to set the value to a field.

  1. Add default value to respective field

  2. If the field is available in other Linked field Doctype. Use

    e.g. cur_frm.add_fetch("link_fieldname", "source_field", "target_field")

  3. set_value function,

    e.g. cur_frm.set_value("field", "value")

Dear Sangram,

Thank you for your response.

This will only work if i have a default field in user section.
In my case the value of user field depends on the dropdown field value.
Image attached for your reference.

Appreciate your support & reference.


just tested on my local instance, it works as expected

  1. create a new email alert like below if you would like to set the owner when creating a new lead

    please make sure there is valid recipients set, otherwise per program logic, the property set will be ignored

if you would like to trigger the owner assign when out_door_source is changed after initial creation, then another email alert with “send alert on” as Value Change, change field as Out_Door_Source, others are the same.

  1. create new lead or change existing lead , choose Under Construction Office for out door source field, after save, the owner field will be auto populated with the assigned value in email alert setting!

Dear Szufisher,

Thank you so much for your support.
It works Great and the solution is very easy.

Appreciate your detailed response on the solution.

Have a good day.

1 Like

Hi there,

I need help with something,

I have a custom field (supp_bill_no) in doc Purchase Receipt. I need to fetch this data in a field (bill_no) in Doc Purchase Invoice.

I have tried using fetch from by entering purchase_receipt.supp_bill_no in bill_no field, but it doesnt help.

Also tried making custom script in doc type Purchase invoice using
frappe.ui.form.on(‘Purchase Invoice’, {
refresh(frm) {
cur_frm.add_fetch(“supp_bill_no”, “supp_bill_no”, “bill_no”)

But it doent help either.

Can anyone help me with this small issue please