oTrans.Update() with no Row?

I’m dipping my toe into the waters of creating some coded customizations. I want a button on the POHeader that when pressed, creates a new header and auto-fills the vendor for an ICPO. I cannot manage to get the button press to trigger the Update method.

int count = 0;
private void epiButtonICPO_Click(object sender, System.EventArgs args)
{
EpiDataView edvPOHeader = (EpiDataView)(this.oTrans.EpiDataViews["POHeader"]);
System.Data.DataRow edvPORow1 = edvPOHeader.CurrentDataRow;
if(newICPO() == true)
{
count +=1;
((EpiDataView)oTrans.EpiDataViews["CallContextBpmData"]).dataView.Table.Rows[0]["Number09"] = count;
//string testString = Convert.ToString(count);
//MessageBox.Show(testString);

oTrans.Update();
}
}

Hi Dave, I think I’m missing something. oTrans.Update() is equivalent to saving changes in a form, but it looks like your button is loading a new PO. Is oTrans.Refresh() closer to what you’re trying to do?

Hello Kevin!
It certainly could be! I don’t have experience with this kind of thing and only got this far by googling and stringing together other peoples pieces.
I am trying to get this code to trigger a BPM on the update method. oTrans.Update() not working because there’s no rows, and nothing to save, makes sense. I did have oTrans.Refresh() earlier today and this also did nothing.

You’ll need to update the row mod to “U” (updated) so it knows (or thinks anyways) that there is something to update.

So getting a form button to create a new record can definitely be done, but it gets pretty complex. What I’d suggest would be have your users create a new PO using the “new” Toolbar button, as they normally would, and then have the button auto-fill the vendor. You could add validation to make sure it’s a new row ( PO Number field == 0 ) along with your newICPO() method. Then when you call oTrans.Update(), it should have the new row record ready, and execute as expected.