Thofste - Monday, June 15, 2015 8:12 AM:
Hi all,
I'm trying to build a sequence and using the year as a prefix.
After each year the sequence needs to restart a beginning with 0 or 1.
After running and debugging the script it will hang.
When starting a new action and click on save the following server method will start.
Innovator inn = this.getInnovator();
if (this.getAction() == "add")
{
//System.Diagnostics.Debugger.Break();
//Get the prefix of the sequence who needs to be reset every year
Item res_seq = this.newItem("sequence","get");
res_seq.setProperty("keyed_name","aer_action_8D");
res_seq = res_seq.apply();
string prefix_seq = res_seq.getProperty("prefix","");
//Get current year
string Year = DateTime.Now.Year.ToString();
Year = Year + "-";
//If the prefix isn't equal change the prefix and reset
if (prefix_seq != Year){
res_seq = this.newItem("sequence","edit");
res_seq.setAttribute("where","[sequence].name='aer_action_8D'");
res_seq.setProperty("prefix",Year);
res_seq.setProperty("current_value","1");
res_seq = res_seq.apply();
}
//Get next Sequence and use the field item_number to put it in.
string nextseq = inn.getNextSequence("aer_action_8D");
string item_number = this.getProperty("item_number", "");
this.setProperty("item_number",nextseq);
}
return this;
When the if statement is skipped it works, and when we skip the getNextSequence (putting the last three lines in comments) it works and it's changing the prefix correctly.
If tested and set prefix on 2014- and then running the script.
I hope some one has done something like this before and could help me.
Best regards,
Tom Hofste
Thofste - Wednesday, June 17, 2015 1:55 AM:
Hi All,
This is a solution but could someone tell me why you can't use the inn.getNextSequence directly after changing the Sequence.
Innovator inn = this.getInnovator();
if (this.getAction() == "add")
{
//System.Diagnostics.Debugger.Break();
//Get the prefix of the sequence who needs to be reset every year
Item res_seq = this.newItem("sequence","get");
res_seq.setProperty("keyed_name","aer_action_8D");
res_seq = res_seq.apply();
string prefix_seq = res_seq.getProperty("prefix","");
//Get current year and set prefix variable
string Year = DateTime.Now.Year.ToString();
string res_prefix = Year + "-";
if (prefix_seq != res_prefix){
//Reset the sequence
res_seq = this.newItem("sequence","edit");
res_seq.setAttribute("where","[sequence].name='aer_action_8D'");
res_seq.setProperty("prefix",res_prefix);
res_seq.setProperty("current_value","1");
res_seq = res_seq.apply();
//Build the first sequence it doesn't to get te sequence after a change
string item_number = this.getProperty("item_number", "");
this.setProperty("item_number",res_prefix + "001");
} else {
// Get current Item Number to set sequence
string nextseq = inn.getNextSequence("aer_action_8D");
string item_number = this.getProperty("item_number", "");
this.setProperty("item_number",nextseq);
}
}
return this;
Best regards,
Tom