I have some modifications to new features

Mar 30 at 6:44 AM
Edited Apr 3 at 6:49 AM
1) add symbol current year to Suffix or Prefix - [YYYY] - 4 number year, [YY] - 2 number year (for example C-[YY] generating text C-17 in year 2017)
2) choosing reset number counter to value "IncrementBy" (as usual number 1) every year

Add two fields to au_counterconfiguration :
1) au_resetnumber - bool , choose, if you need reset counting yearly (add this field to the Form)
2) au_lastactivity - DateTime, last activity with numbering (need for reset counter)

And my modified code:
            if (messageName == "Create")
            {
                int currentYear = DateTime.Now.Year;
                StringBuilder stringBuilder = new StringBuilder();

                //add prefix               
                string Prefix = _counterEntity.au_Prefix?.Replace("[YYYY]", currentYear.ToString());
                Prefix = Prefix?.Replace("[YY]", currentYear.ToString().Substring(2));
                stringBuilder.Append(Prefix);

                //check increment by                    
                Incrementby = _counterEntity.au_IncrementBy;

                //set next number with or without zeropads                    
                if (_counterEntity.au_resetnumber == null || _counterEntity.au_lastactivity == null || !_counterEntity.au_resetnumber.Value || _counterEntity.au_lastactivity.Value.Year == currentYear)
                    Nextnumber = _counterEntity.au_NextNumber;
                else
                    Nextnumber = Incrementby;

                if (!_counterEntity.au_ZeroPad.Value)
                {                        
                    stringBuilder.Append(Nextnumber.ToString());
                }
                else
                {                        
                    string str1 = Nextnumber.ToString();
                    stringBuilder.Append(str1.PadLeft(_counterEntity.au_Length.Value, '0'));
                }

                //add suffix                   
                string Suffix = _counterEntity.au_Suffix?.Replace("[YYYY]", currentYear.ToString());
                Suffix = Suffix?.Replace("[YY]", currentYear.ToString().Substring(2));
                stringBuilder.Append(Suffix);

                //set next number
                _counterEntity.au_NextNumber = new int?(Nextnumber.GetValueOrDefault() + Incrementby.GetValueOrDefault());

                //clean entity id (process is finished, the current record will be free)
                _counterEntity.au_entityid = null;

                //last activity with getting number
                _counterEntity.au_lastactivity = DateTime.Now;

                //update counter entity
                _trace.Trace("Action: Update counter record");
                _orgService.Update(_counterEntity);                    

                //set counter to field in callingEntity
                _trace.Trace("Action: set field name with value " + stringBuilder.ToString());
                _callingEntity.Attributes[_counterEntity.au_FieldName] = stringBuilder.ToString();
            }
Coordinator
Jun 4 at 4:24 PM
Added this one too. Thanks!