Nian - Monday, July 11, 2011 8:11 AM:
Good day
We will be importing lagacy data that has unique 6-digit numbers, but they are in large block of sequencial numbers with large unused blocks in between. These numbers will be assigned to a specific custom property.
I have already set up a sequence in Aras that would increment by one, and assigned to the same property for new instances - set to unique.
I want the sequence to start at zero and find the next available number, resulting in us being able to fill all the unused numbers in our legacy sequence. Currently it would only warn the user if the number is already in use, and leave it there.
How do I do this checking and assigning before the instance gets created? Some sample code would help me a lot, if possible.
Thank you
Nian
Brian - Tuesday, July 12, 2011 6:43 AM:
Hi Nian,
Unless you have a small list of the available unused blocks it is a bit messy but you could do this.
Set the property to string not sequence. That way you can fill it in yourself instead of the Server doing it on save.
In an "onBeforeAdd' triggered method for the Item you need to get the next sequence number:
You can use (c# method)
Innovator inn = this.getInnovator;
bool stopFlag = true;
while (stopFlag){
string nextSeq = inn.getNextSequence("Name of Sequence"); // returns null if not successful
// Now you will need to test if there is an item with this number
Item part = this.newItem("Part","get");
part.setProperty("custom_sequence",nextSeq);
part = part.apply();
if ( part.isEmpty() ){
// there is no item with this number
// break out of the loop. Otherwise keep looking
stopFlag = false;
}
}
this.setProperty("custom_sequence",nextSeq);
return this;
I have assumed that "custom_sequence" is the name of your property.
"Name of Sequence" is obviously the name of the sequence that you set up that you want the next number from.
This code was written in this text box and has not been compiled. It should work but I apologise if there are syntax errors.
Hope this helps.
BTW this also answers part of your other question in the other thread. Sequences are updated by the server. If you want to concatenate a number before the server has created the sequence then you need to do the same sort of thing as above and not set the Property to data type Sequence.
Cheers,
Brian.