Trouble with a callcontext field

Good morning!
I am having trouble setting the value of a CallContextBpmDataRow. I am using a custom form to populate UD08 with values. Most of my values get added to the table just fine, but now I want to add an incrementing Unique ID field and it is giving me problems.

For starters, here is the code to add the values to edvCallContextBpmDataRow and then fire off the BAQ custom action that utilizes the stored values. Below is also a function to pull the last Unique ID value from UD08.

private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		//Verify text values before adding record
		if (txtMyJob.Text == "")
		{
		MessageBox.Show("Job Missing!");
		return;
		}
		if (cmbMyPart.Text == "")
		{
		MessageBox.Show("Part Missing!");
		return;
		}		
		if (cmbMyOp.Text == "")
		{
		MessageBox.Show("Op Missing!");
		return;
		}
		if (cmbRGID.Text == "")
		{
		MessageBox.Show("Resource Group Missing!");
		return;
		}			
		if (Convert.ToDouble(epiNumericEditorC1.Value) == 0.0)
		{
		MessageBox.Show("Old Production Standard Missing!");
		return;
		}
		if (Convert.ToDouble(epiNumericEditorC2.Value) == 0.0)
		{
		MessageBox.Show("New Production Standard Missing!");
		return;
		}
		if (epiTextBoxC2.Text == "")
		{
		MessageBox.Show("Description Missing!");
		return;
		}
		if (epiTextBoxC3.Text == "")
		{
		MessageBox.Show("Employee Missing!");
		return;
		}
		if (epiDateTimeEditorC1.Value == null)
		{
		MessageBox.Show("Date Missing!");
		return;
		}

		int NextUNID = 0;
		EpiDataView edvCallContextBpmData = ((EpiDataView)(this.oTrans.EpiDataViews["CallContextBpmData"]));
		System.Data.DataRow edvCallContextBpmDataRow = edvCallContextBpmData.CurrentDataRow;
		edvCallContextBpmDataRow["Character01"] = txtMyJob.Text;
		edvCallContextBpmDataRow["Character02"] = cmbMyPart.Text;
		edvCallContextBpmDataRow["Character03"] = cmbMyOp.Text;	
		edvCallContextBpmDataRow["Character04"] = epiTextBoxC2.Text;	//description
		edvCallContextBpmDataRow["ShortChar01"] = cmbRGID.Text;		
		edvCallContextBpmDataRow["Date01"] = epiDateTimeEditorC1.Value;
		edvCallContextBpmDataRow["Number01"] = epiTextBoxC3.Text; // emp id
		edvCallContextBpmDataRow["Number02"] = epiNumericEditorC2.Value; // new prod time
		edvCallContextBpmDataRow["Number03"] = epiNumericEditorC1.Value; //old prod time
		edvCallContextBpmDataRow["Number04"] = epiNumericEditorC3.Value; //old set time
		edvCallContextBpmDataRow["Number05"] = epiNumericEditorC4.Value; // new set time
		NextUNID = getLastUNID() + 1;
		MessageBox.Show("Adding UNID: " + NextUNID.ToString());	
		edvCallContextBpmDataRow["Number10"] = Convert.ToInt32(NextUNID);
		var edvV = oTrans.Factory("V_CPI_1View");
		BAQRunCustomAction(edvV, "AddRow");
 	   RefreshPage();
	}





private int getLastUNID()
{
		int UNID = 0;
		DynamicQueryAdapter qry = new DynamicQueryAdapter(oTrans); 
		qry.BOConnect();

		qry.ExecuteByID("LastCPIUNID");	
	    DataSet ds = qry.QueryResults;
			
			if (Convert.ToString(ds.Tables["Results"].Rows[0]["Calculated_LastUNID"]) == "")
				{		
				MessageBox.Show("No previous UNID found. Starting at 0.");	
				qry.Dispose();				
				return 0;
				}
			else
				{
				UNID = Convert.ToInt32(ds.Tables["Results"].Rows[0]["Calculated_LastUNID"]);
				MessageBox.Show("Previous UNID found. Incrementing from " + UNID.ToString());
				qry.Dispose();
				return UNID;
				}	

}

Once the data is submitted on the dashboard, and the button is clicked, the BAQ custom action takes over the updating part. In the BPM, I have a couple of simple custom code widgets as follows:

using(var UD08svc = Ice.Assemblies.ServiceRenderer.GetService<UD08SvcContract>(Db))
{
UD08Tableset ds = new UD08Tableset();
UD08svc.GetaNewUD08(ref ds);
ds.UD08[0].Key1 = callContextBpmData.Character01; // job
ds.UD08[0].Key2 = callContextBpmData.Character02; // part
ds.UD08[0].Key3 = callContextBpmData.Character03; // op
ds.UD08[0].ShortChar01 = callContextBpmData.ShortChar01; // RGID 
ds.UD08[0].Date01 = callContextBpmData.Date01;    // change date
ds.UD08[0].Number01 = Convert.ToInt32(callContextBpmData.Number01); // empid
ds.UD08[0].Number02 = Convert.ToDecimal(callContextBpmData.Number02); // new prodtime
ds.UD08[0].Number03 = Convert.ToDecimal(callContextBpmData.Number03); // old prodtime
ds.UD08[0].Number05 = Convert.ToDecimal(callContextBpmData.Number05); // new settime
ds.UD08[0].Number04 = Convert.ToDecimal(callContextBpmData.Number04); // old settime
ds.UD08[0].Character01 = callContextBpmData.Character04; // description

ds.UD08[0].Number10 = callContextBpmData.Number10; // unid
ds.UD08[0].Key5 = Convert.ToString(callContextBpmData.Number10); //unid for key
UD08svc.Update(ref ds);
}

No matter what I try, I always get a value of 0 in Number10.
Here is the BAQ that looks up the last CPI UNID:

select 
	(max(UD08.Number10)) as [Calculated_LastUNID]
from Ice.UD08 as UD08

Am I missing something obvious here? All my other callcontext values pull into UD08 just fine. But I can’t seem to get a value into Number10 or Key5. You can see several message boxes for debugging. In the GetLastUNID() part, the “Previous UNID Found, incrementing from 0” message shows. Then, inside the button click the message box shows “Adding UNID: 1”. But the number10 call context doesn’t save the 1 value. I put a message box in the BPM before I ran the code above, and number10 = 0.
I have gone around and around trying various workarounds. What did I miss?
Thanks for your time!
Nate

EDIT: I think the problem must be within this section of the customization code:

		MessageBox.Show("Adding UNID: " + NextUNID.ToString());	
		edvCallContextBpmDataRow["Number10"] = Convert.ToInt32(NextUNID);

Here the message box returns “1”, but number10, doesn’t. I have taken out the convert toint32 but that didn’t make a difference. Why could I set a value from a textbox, but not from a variable? This line sets the value just fine:

edvCallContextBpmDataRow["Number01"] = epiTextBoxC3.Text; // emp id

This is so strange! Thanks for looking into it with me.

Nate, you are already server side, just use a simple query to get your Max value instead of calling a BAQ on the front end to accomplish this.

I guess I am not sure how to do that!

What table holds your sequence?

UD08.Key5 should hold the UNIDs. That’s really all I want is a unique value in key5 to uniquify the records.

IF you want a unique value just go with Guid.NewGuid().ToString() no query necessary

If you want a Sequence, just do (from x in Db.UD05 select x.Key5).Max();

The GUID is what I needed! Thanks Jose!