Auto numbering not working

Hi Can someone help me with this auto numbering javascript code its not working even I followed all the things that it says on its site.

here is the code:

| (function() { |
|   | ‘use strict’; |
|   |   |
|   | function autoNum(event) { |
|   | var record = event.record; |
|   |   |
|   |   |
|   | var dt = record[‘Date_for_auto_num’].value; |
|   | var dtyy = dt.substring(0, 4); |
|   | var dtmin = dtyy + ‘-01-01’; |
|   | var dtmax = (parseInt(dtyy, 10) + 1) + ‘-01-01’; |
|   |   |
|   |   |
|   | var query = { |
|   | ‘app’: kintone.app.getId(), |
|   | ‘query’: ‘Date_for_auto_num >= "’ + dtmin + ‘" and Date_for_auto_num < "’ + dtmax + ‘" order by Auto_num desc limit 1’ |
|   | }; |
|   |   |
|   |   |
|   | return kintone.api(kintone.api.url(’/k/v1/records’, true), ‘GET’, query).then(function(resp) { |
|   | var records = resp.records; |
|   |   |
|   |   |
|   | if (records.length > 0) { |
|   | var rec = records[0]; |
|   | var autono = rec[‘Auto_num’].value; |
|   | autono = parseInt(autono.substring(3), 10) + 1; |
|   | autono = ‘00000’ + autono; |
|   | autono = dt.substring(2, 4) + ‘-’ + autono.substring(autono.length - 5); |
|   | event.recor[‘Auto_num’].value = autono; |
|   |   |
|   | } else { |
|   | event.record[‘Auto_num’].value = dt.substring(2, 4) + ‘-00001’; |
|   | } |
|   | return event; |
|   | }).catch(function(e) { |
|   | alert('Error occured getting record - error: ’ + e.message); |
|   | return false; |
|   | }); |
|   | } |
|   |   |
|   |   |
|   | kintone.events.on(‘app.record.create,submit’, autoNum); |
|   |   |
|   |   |
|   | kintone.events.on(‘app.record.create.show’, function(event) { |
|   | var record = event.record; |
|   |   |
|   | record[‘Auto_num’].disabled = true; |
|   | return event; |
|   | }); |
|   |   |
|   | kintone.events.on([‘app.record.edit.show’, ‘app.record.index.edit.show’], function(event) { |
|   | var record = event.record; |
|   |   |
|   | record[‘Auto_num’].disabled = true; |
|   | record[‘Date_for_auto_num’].disabled = true; |
|   | return event; |
|   | }); |
|   |   |
|   |   |
|   |

})();

 

You may refer to this website where I get the code:

https://developer.kintone.io/hc/en-us/articles/115002656914-Custom-automatic-numbering

 

Thank you in advance for the help.

|

Hello Muhaymin,

 

 

I found out that on the 43rd row, right between “create” and “submit” it should be a “.” not a “,”

 

kintone.events.on(‘app.record.create,submit’, autoNum);

kintone.events.on(‘app.record.create.submit’, autoNum);

 

 

Also, on the 30th row the spelling of the word “record” is not correct.

 

event.recor[‘Auto_num’].value = autono;

event.record[‘Auto_num’].value = autono;

 

 

I hope this helps.

@Sean Tachibana 

 

Thank you Sensei!! It finally works!!