Access field information in AfterAdapterMethod "GetByID" method

Hi,

I have a secondary part number UD field in Part. When I read in the part record I need to grab the UD field and use it to look up the description and then stuff it into a text box with no binding.

My script below does it all except get the part number in the UD field to look up the secondary part.

I’ve used an EpiDataView in another event handler to do this, but it looks like the data view hasn’t been set up yet at this point. (?)

How might I grab a field from the part master here?

Thanks,

Joe

private void oTrans_adapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **

// ** Use MessageBox to find adapter method name
// EpiMessageBox.Show(args.MethodName)
MessageBox.Show("args.Methodsname " + args.MethodName);
switch (args.MethodName)
{
case "Update":
break;
case "GetByID":
MessageBox.Show("entering get by id");
EpiDataView edv = ((EpiDataView)(oTrans.EpiDataViews["Part"])); // GET DATA VIEW
if (edv == null) MessageBox.Show("null epidataview"); // IT'S NOT NULL
bool recSelected = false;

//string whereClause = "PartNum = '" + txtServicePartUsePart.Text + "'";
string whereClause = "PartNum = '" + edv.dataView[edv.Row]["ServicePartUsePart_c"] + "'"; // THIS LINE DOES A BAD THING (Is This a New Record?)
//string whereClause = "PartNum = '" + "021497" + "'"; This works just fine, but...
MessageBox.Show("whereClause" + whereClause);

DataSet dsPart = Ice.UI.FormFunctions.SearchFunctions.listLookup(oTrans, "PartAdapter", out recSelected, false, whereClause);
MessageBox.Show("after dataset");
if (recSelected)
{
MessageBox.Show("recSelected " + recSelected.ToString());
txtServicePartUsePartDesc.Text = Convert.ToString(dsPart.Tables[0].Rows[0]["PartDescription"]);
}

else
{
txtServicePartUsePartDesc.Text = "";
}
MessageBox.Show("exiting get by id");

break;
}

}

May be you must convert to String this line too. Like this

string whereClause = “PartNum = '” + edv.dataView[edv.Row][“ServicePartUsePart_c”].ToString() + “'”;

Jackie,

Thanks for the catch. I had something like that else where in that same format and it worked there. I pasted your version in. And even wrapped it in a Convert.ToString(). But when I execute any form of that line in this event handler I get a message box that reads: Record not found. Add new? Yes/No

Then when I answer “no” I get a box that says "Index -1 is either negative or above rows count.

I’m wondering if the dataview isn’t set at this point. Maybe?

Cheerfully accepting all suggestions. :slight_smile:

Thanks,

Joe