Interesting question from a Seeqer who would like to create a BatchID for each batch with the format YYYYMMDDS# where YYYY is the year, MM is month, DD is day, S is the shift and # is the order of the batch in that shift.
This is one of the possible method.
STEP 1: Create the signal for YYYYMMDD
//STEP1: Trend the "Start" date of each capsule
$StartDate = $batch
.move(7h) //based on time zone use in workbench.
.toSignal('Start')
.toString()
.move(-7h) //move back the signal to the original position
//STEP2: Replace the format to YYYYMMDD
$YYYYMMDD = $StartDate
.replace('/^(..........).*/' , '$1') //example of the output is 2022-09-02
.replace('-','') //20220902
.validValues()
.toStep(1d)
$YYYYMMDD
STEP 2: Create the signal for S which represent the shift number
combinewith(
shifts (6, 12, "Asia/Kuala_Lumpur").setProperty('Shift','1'),
shifts(18, 12, "Asia/Kuala_Lumpur").setProperty('Shift','2'))
Followed by another formula,
$s.toSignal('Shift')
STEP 3 : Create the # which represent batch sequence in the respective shift
$count = $batch.aggregate(count(),$batch, startkey(),0s)
$count
.runningCount($shift)
.toStep(1d)
.toString()
STEP 4 : Create the BatchID and set as property
$BatchID = $YYYYMMDD + $S + $x
$batch.setProperty('BatchID', $BatchID, StartValue())