Name of month from date

Hi everybody,
I need to get name of month from the date.

I created extra field with number of month and then tried someting like this on model change:

if(doo.model.mesicNastupuCislo.value === 1){
    doo.model.mesicNastupu.setValue('leden');
};
 if(doo.model.mesicNastupuCislo.value === 2){
    doo.model.mesicNastupu.setValue('únor');
};
 if(doo.model.mesicNastupuCislo.value === 3){
    doo.model.mesicNastupu.setValue('březen');
};
 if(doo.model.mesicNastupuCislo.value === 4){
    doo.model.mesicNastupu.setValue('duben');
};
 if(doo.model.mesicNastupuCislo.value === 5){
    doo.model.mesicNastupu.setValue('květen');
};
 if(doo.model.mesicNastupuCislo.value === 6){
    doo.model.mesicNastupu.setValue('červen');
};
 if(doo.model.mesicNastupuCislo.value === 7){
    doo.model.mesicNastupu.setValue('červenec');
};

if(doo.model.mesicNastupuCislo.value === 8){
doo.model.mesicNastupu.setValue(‘srpen’);
};
if(doo.model.mesicNastupuCislo.value === 9){
doo.model.mesicNastupu.setValue(‘září’);
};
if(doo.model.mesicNastupuCislo.value === 10){
doo.model.mesicNastupu.setValue(‘říjen’);
};
if(doo.model.mesicNastupuCislo.value === 11){
doo.model.mesicNastupu.setValue(‘listopad’);
};
if(doo.model.mesicNastupuCislo.value === 12){
doo.model.mesicNastupu.setValue(‘prosinec’);
};

It seems to work, but definetely not how I expected: sometimes it is kinda lazy. I change the date to 10, the name field does nothing, then I change the date to 3 and the name field changes to “říjen”.

I need the name to change dynamically and correctly. Can you tell me how to fix this? Maybe there is also another way to achieve that goal.

Thanks a lot!
Martina

Hi Martina,

I used the same code you write here and it behaves as I would expect don’t you have some other script that could affect the behavior?

(async (doo: IDoo) => { // do not change this line
// place your code here
if(doo.model.mesicNastupuCislo.value === 1){
doo.model.mesicNastupu.setValue(‘leden’);
};
if(doo.model.mesicNastupuCislo.value === 2){
doo.model.mesicNastupu.setValue(‘únor’);
};
if(doo.model.mesicNastupuCislo.value === 3){
doo.model.mesicNastupu.setValue(‘březen’);
};
if(doo.model.mesicNastupuCislo.value === 4){
doo.model.mesicNastupu.setValue(‘duben’);
};
if(doo.model.mesicNastupuCislo.value === 5){
doo.model.mesicNastupu.setValue(‘květen’);
};
if(doo.model.mesicNastupuCislo.value === 6){
doo.model.mesicNastupu.setValue(‘červen’);
};
if(doo.model.mesicNastupuCislo.value === 7){
doo.model.mesicNastupu.setValue(‘červenec’);
};
if(doo.model.mesicNastupuCislo.value === 8){
doo.model.mesicNastupu.setValue(‘srpen’);
};
if(doo.model.mesicNastupuCislo.value === 9){
doo.model.mesicNastupu.setValue(‘září’);
};
if(doo.model.mesicNastupuCislo.value === 10){
doo.model.mesicNastupu.setValue(‘říjen’);
};
if(doo.model.mesicNastupuCislo.value === 11){
doo.model.mesicNastupu.setValue(‘listopad’);
};
if(doo.model.mesicNastupuCislo.value === 12){
doo.model.mesicNastupu.setValue(‘prosinec’);
};
}) // do not change this line

With Regards,

Filip

Hi Filip,
thanks for your advice. I tried it again. It the value doen’t change on 1st change, but when I open the record and save it again, it changes. I was thinkig this way:

  • I have a field with date.
  • Then calculated field with number of month
  • Then field with name of the month

Is it possible that the delay is because the step between number and the date? That when I change the date, the number field is not yet changed?

Hi,

the Calculated field is calculated only after the record is saved, i.e. then the script is executed only on the second view. But the same script can be used without the counted field, like my example above.

Yes, but mesicNastupuCislo is calculated from the date field. So this could be the issue?

Yes, that’s right mesicNastupuNumber is calculated after the record is saved and then the script is not executed.