Manufacturing Date as Batch ID in specific format


I am trying to set my batch ID as the Manufacturing Date in a specific format : YYMMDD-##

I have created a custom field in Batch Doctype called : batch_date

Here is the client script I created but it does not work :

frappe.ui.form.on('Batch', {
	refresh(frm) {
		cur_frm.set_value("batch_date", frappe.datetime.(doc.manufacturing_date).format("YYMMDD-##"))

Can somebody help me?

Thank you!

Hi @FredericVerville,

You can’t set it because the datatype of a date is set from System Setting.

Please check it.

Thank You!

If your date of creation of the batch is same as manufacturing date then you can just add a naming series for it. DD is available in the naming series for current day.

Test it out separately, maybe this is better solution than custom scripts.


Thank you for your answer.

The problem with Naming Series with manufacturing date is that it won’t have the format : YYMMDD-##

How can I have this format?

Thank you!

Hi @FredericVerville,

First, apply a custom/client script.
When you select manufacturing_date then batch_date update in YYMMDD format.

frappe.ui.form.on('Batch', {
	manufacturing_date(frm) {
		var ymd = frm.doc.manufacturing_date;
        var yy = ymd.substring(2,4);
        var mm = ymd.substring(5,7);
        var dd = ymd.substring(8,10);

Then set naming series format like:


Thank You!

Thank you so much for your help @NCP

I have tried your solution, but there is still some problems.

The problem is that we use automatic batch creation and it doesn’t seems to work when we do a “Purchase Receipt” :

Your script work well, but the field “Batch Date” only update when the field “Manufacturing Date” is updated manually and it seems to not work with automatic batch creation :

Here is the naming Series I am using :

Thank you so much for your help!

Hi @FredericVerville,

duplicate them and create a another script like:
manufacturing_date(frm) { → onload(frm) {

Both scripts run when opening a new batch then automatically set the date and also set to change the manufacturing date.

Automatic batch for set series only so I don’t think it will work.

Thank You!