Forum Discussion
Meismart
8 years agoCreator III
Now you understand the concept, it is possible to automatically create and use the sequences.
(Note that you cannot create a sequence and call get next sequence in the same Method due to a clash creating and using the sequence)
Something similar to:
//sequence 1
Item seq1 = inn.newItem("Sequence","get");
seq1.setProperty("name","mySequence_" + this.getProperty("classification","default"));
seq1 = seq1.apply();
//if not found, add a new sequence
if(seq1.getItemCount()<1)
{
seq1 = inn.newItem("Sequence","add");
seq1.setProperty("name","mySequence_" + this.getProperty("classification","default"));
//update the following to match your requirements//
string pre = "pre"
seq1.setProperty("prefix",pre);
string suf = "suf"
seq1.setProperty("suffix",suf);
string curVal = "1"
seq1.setProperty("current_value",curVal );
string pad = "0"
seq1.setProperty("pad_with",pad);
int padto = 9
seq1.setProperty("pad_to",padto.ToString());
seq1.setProperty("step","1");
//end of update//
seq1 = seq1.apply();
//set the new sequence number on the part must match the new sequence above
string s = "";
//adjust padto if using more than 1 digit in curVal
for (int i = 0; i<padto; i++)
{
s+=pad;
}
s = pre+s+curVal+suf
this.setProperty("item_number", s);
}
else
{
//if found, get the next sequence number
string s = inn.getNextSequence(seq1.getProperty("name",""));
//set the new sequence number on the part
this.setProperty("item_number", s);
}