Naming Series Update via Code

Hi all,
Don’t know if there is a way of updating all or based on a list update the Naming Series.

Right now i need to update SI, PE, GL, STE to different ones but not by going to every Database (client) via GUI (Setup - Naming Series - Doctype…) but would be great to have a way of updating those via code or API, and to make sure that those are a the default selected.

Hello @Helio_Jesus,

You can set the value for any doctype via a frappe call. Please find the code below!

frappe.call({
		method: "frappe.client.set_value",
		async:false,
		args:{
			'doctype':'Bill Booking', // Naming Series
			'name':referenceTable.reference_name, // where clause for the name to be matched
			'fieldname':'outstanding_amount', // fieldname to be set
			'value':valueToUpdate // value to be set for the fieldname
		},
		callback: function (updateOutstanding) {
			if(updateOutstanding.message != undefined){
				console.log("Updated outstanding value") // updated the series value
			}
		}
	})

Thanks & Regards,
Kalpit

@Shah_Kalpit thanks for your reply but that is not what i am trying to achieve…
My point is how to add Naming Series to Sales Invoice, Payment Entry as most of the Customers have different requests but now this is a must that for Sales Invoice all must start with FTXXXXX and al Payment Entry must start with RCXXXX as you can see the below image this was done via going to Setup - Naming Series …

The point here to to achieve the same via code but being able to set to other Doctypes.

By far what I have understood is that you want to give different naming series to different doctype via code. Right?


Make these changes. What you need to do is make one field named customer_code which will be responsible for generating the auto name according to your format.

On onload event, make this frappe call
For the below code to work, you need to make the function getseries as a whitelist method by adding
@frappe.whitelist() just above the def getseries. You can find getseries in the file named naming.py

frappe.call({
        method: "frappe.model.naming.getseries",
        async: false,
        args: {
            'key': 'CUST-',
            'digits': 7
        },
        callback: function (r, rt) {
            if (r.message != undefined) {
                newCustomerCode = "CUST-" + r.message;
                cur_frm.doc.customer_code=newCustomerCode;
                cur_frm.refresh_field('customer_code');
            }
        }
    });

Thanks & Regards,
Kalpit

Yes that is what I want to change the series of Sales Invoice, Payment Entry… Via coding…

The solution proposed implies adding additional Field to Sales invoice, payment entry and all other doctype. Can it be achieved without extra field?

Because GUI you just select the Doctype and type the new series format.

Okay, I too don’t know!
Going to each doctype and updating the field of autoname (SO.####) helps too!

Thanks & Regards,
Kalpit Shah