Incremental ID Number

0
Hello everyone, I want to ask about change value for incremental ID   I have an entity with this attribute   I have a logic to retrieve incremental AlarmID like below   Here the complete code if (parseInteger(substring($LatestAlarm/AlarmID, 9)) < 9) then    'ALR-'+parseInteger(formatDateTime(trimToYears([%CurrentDateTime%]),'yyyy'))+'-000' + toString(parseInteger(substring($LatestAlarm/AlarmID, length($LatestAlarm/AlarmID) - 4)) + 1) else if (parseInteger(substring($LatestAlarm/AlarmID, 9)) < 99) then    ' ALR-'+parseInteger(formatDateTime(trimToYears([%CurrentDateTime%]),'yyyy'))+'-00' + toString(parseInteger(substring($LatestAlarm/AlarmID, length($LatestAlarm/AlarmID) - 4)) + 1) else if (parseInteger(substring($LatestAlarm/AlarmID, 9)) < 999) then    'ALR-'+parseInteger(formatDateTime(trimToYears([%CurrentDateTime%]),'yyyy'))+'-0'+toString((parseInteger(substring($LatestAlarm/AlarmID, length($LatestAlarm/AlarmID) - 4)) + 1)) else    'ALR-'+parseInteger(formatDateTime(trimToYears([%CurrentDateTime%]),'yyyy'))+'-'+toString((parseInteger(substring($LatestAlarm/AlarmID, 9)) + 1))   This is how I retrieve $LatestAlarm   It run smoothly from AlarmID = ALR-2024-0001 to ALR-2024-9999. But when the latest data is ALR-2024-10000, when I inserted next data, it still throws ALR-2024-10000 not ALR-2024-10001   Can anyone give me insight for this logic?
asked
2 answers
0

Hi, Fadil Fidrian

 

Before Change Activity take retrieve activity and list aggregative count pass the 'ALR-'+parseInteger(formatDateTime(trimToYears([%CurrentDateTime%]),'yyyy'))+'-000' + toString(parseInteger(substring($LatestAlarm/AlarmID, length($LatestAlarm/AlarmID) - 4)) + 1).

apply like below.

length($LatestAlarm/AlarmID) - 4)) + 1).  count +1)

I hope it will help you.

 

Thank you!

answered
0

May i suggest another approach to avoid the complexity of parsing strings?

 

I would suggest having a separate autonumber attribute, or an integer that you increment yourself.

Then you only need to concatenate values and put the result into your string attribute.

 

Also, you can use the StringLeftPad action from community commons to add leading zeros if needed.

 

'ALR-' + formatDateTimeUTC([%CurrentDateTime%],'yyyy') + '-' + $numberWithLeadingZeros

 

Does this help?

answered