Lead want to save based on company

Hello guys

I want to save leads in different naming series.

I connected the lead with API so the lead will get from different companies’ websites automatically saving the contact us, so I want to save the lead based on the company.
I added some custom scripts.

before_save:function(frm)
{
if(frm.doc.company==" Company 1")
{
frm.set_value(“naming_series”,“CF-DXB-.YYYY.-”)
}
else if (frm.doc.company==" Company 2")
{
frm.set_value(“naming_series”,“CF-EKM-.YYYY.-”)
}
},

But it is not working. Please help me with this also I want to change the company field position to above from more information so for that I edit the JSON file (lead.json) and migrate no error found but the poison of company did not change

Please help me to find any solutions

Hi @jinsy,

Please check it.

frappe.ui.form.on('Lead', {
     company(frm) {
         if (frm.doc.company == "Company 1") {
             frm.doc.naming_series = "CF-DXB-.YYYY.-";
         }
         else {
             frm.doc.naming_series = "CF-EKM-.YYYY.-";
         }
    	}
});

Thank You!

Thanks for the quick response :slightly_smiling_face: but it is not working

Please try to change trigger then check.

Or

First check to when manually create lead then it’s work or not?

Thanks.

Sorry for that.

In my side only work before_save trigger so you can use before_save then check it.

before_save(frm){

Thanks.

I did it manually it is working but when leads come from the website it saves in one naming series

use server script for same

Hello
I’m new to this field, can you please explain how to apply the server script