This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Program Hangs when I try to create and use a sequence (c#)

Martin Fraser - Tuesday, December 23, 2014 4:26 AM:

1) Part and Prog are found earlier in the code, and each is a single Item (tested).
2) The code compiles ok

(see Code):

Item seq1

= inn.newItem("Sequence","get");
seq1
.setProperty("name","mf_Go" + Prog.getProperty("hum_program_code","") + "1");
seq1
= seq1.apply();

if(seq1.getItemCount()<1)
{
seq1 = inn.newItem("Sequence","add");
seq1
.setProperty("name","mf_Go" + pcode + "1");
seq1
.setProperty("prefix","PU");
seq1
.setProperty("suffix",pcode);
seq1
.setProperty("current_value","0");
seq1
.setProperty("pad_with","0");
int a = 9 - pcode.Length;
seq1
.setProperty("pad_to",a.ToString());
seq1
.setProperty("step","1");
seq1
= seq1.apply();
}

if(seq1.getItemCount()==1)
{

//Code hangs here

string s = inn.getNextSequence(seq1.getProperty("name",""));
part.setAction("edit");
part.setProperty("hum_go_contract_number", s);
part = part.apply();
} 

3) querying seq1 at the point it hangs returns the Item:

12/23/2014 8:44:51 AM :
Seq1a: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><Result><Item type="Sequence" typeId="2B46201802CE46708C269667DB4798AC" id="C75B1E5A553847EEB545F12D9FC192C4"><config_id keyed_name="mf_Go2FE1" type="Sequence">C75B1E5A553847EEB545F12D9FC192C4</config_id><created_by_id keyed_name="Martin Fraser" type="User">6F389407246440B7B40D37D4C9ACFEDE</created_by_id><created_on>2014-12-23T08:44:51</created_on><current_value>0</current_value><generation>1</generation><id keyed_name="mf_Go2FE1" type="Sequence">C75B1E5A553847EEB545F12D9FC192C4</id><initial_value>0</initial_value><is_current>1</is_current><is_released>0</is_released><keyed_name>mf_Go2FE1</keyed_name><major_rev>A</major_rev><modified_by_id keyed_name="Martin Fraser" type="User">6F389407246440B7B40D37D4C9ACFEDE</modified_by_id><modified_on>2014-12-23T08:44:51</modified_on><new_version>1</new_version><not_lockable>0</not_lockable><pad_to>6</pad_to><pad_with>0</pad_with><permission_id keyed_name="Sequence" type="Permission">59DA83671F954A3490C30CD9C9CCE42C</permission_id><prefix>PU</prefix><step>1</step><suffix>2FE</suffix><name>mf_Go2FE1</name></Item></Result></SOAP-ENV:Body></SOAP-ENV:Envelope>

Error: Calling string s = inn.getNextSequence(seq1.getProperty("name","")); causes the database to hang. It does not produce an error and it does not process the next line.

When I search the database the sequence does not exist.

Note: If I did not have permision to add the item, I would get an innovator fault.  Everything appears to work correctly then roll-back to the previous state.

Please help!
Many thanks,
Martin

PS.  Merry Christmas.



Martin Fraser - Tuesday, December 23, 2014 5:51 AM:

Update:

It appears to a race condition, I need to split the code into on before and on after add.

Many thanks,
Martin.



DavidSpackman - Sunday, January 11, 2015 7:37 PM:

Hi Martin, 

 

Although probably not related, it's a good idea  practice to check for any errors after you run the apply.

// Perform the query.
Item results = qryItem.apply();
// Test for an error.
if (results.isError()) 
{
	return innovator.newError("Item not found: " + results.getErrorDetail());
}

Dave



Martin Fraser - Tuesday, January 13, 2015 2:36 AM:

Hi David,

Thank you for the advice.

This is an extract from the Method I have written with the excess code removed to try to avoid confusion.  I use the line:
If (results.getItemCount != 1) return innovator.newError(results.ToString());
I like this as it checks for a single item and fails on anything else (can change to < 1 if you are using collections), I find the single line neat and tidy.

I have spoken to another David from Minerva, an ARAS partner.  He believes this is caused because the ARAS sequence item is being created, but there is stored SQL in th background that is not availible until execution halts.  I don't know what ARAS checks when innovator.getNextSequence() is called, but it appears to pass the tests if the ARAS item exists. 

I have been shown a work around, which is to construct the sequence and increment it manually, then pass the final version of it to the add, so the next time it is run, it continues the sequence.  This ONLY works if the method is called a single time.  ie. if you run an action on 2 items, when processing the 2nd item I am not able to detect that the sequence is not fully created.

Many thanks,
Martin.



DavidSpackman - Tuesday, January 13, 2015 5:04 AM:

Thanks Martin,

I have not had a need to work with sequences in the IOM, good reference.

Another good way to check for collections is to use  isCollection()

David.