Announcement

Collapse
No announcement yet.

reset incremental number on year change by formula

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • reset incremental number on year change by formula

    Hello,
    as in the title asked, I would like to know, if there is a way to reset an incremental number, that I use for different cases, as soon as the year changes. Prefered by formula.
    My number is a combination of letters, incrementing number and year, like: AA-0012022

    I would like to start every year the incrementing number from 001 and the current year.

  • #2
    Hi,

    It's possible for 2022 + 0001.

    If you have a workflow you can create a scheduled workflow with a dummy list report returning 1 record of some entity type (no matter what). Schedule this workflow to run every 1 Jan. Add the action that executes formula script. In the script, change the value of the NextNumber record.

    https://github.com/espocrm/espocrm/b...extNumber.json

    Code:
    $id = record\findOne(
        'NextNumber', 'id', 'asc',
        'fieldName=', 'yourFieldName',
        'entityType=', 'yourEntityType'
    );
    
    $value = number\parseInt(
        string\concatenate(      
            datetime\year(datetime\now()),
            '0001'
        )
    );
    
    record\update('NextNumber', $id, 'value', $value);
    I didn't tested it.

    But it's better to change the year prefix manually in entity manager. There's no ability to change a prefix via formula.
    Last edited by yuri; 08-18-2022, 06:17 PM.

    Comment

    Working...
    X