oTrans.Update() resets value

Hi,

On Purchase Order Entry, we have custom fields to change the Amend Date with reasoning. Behind this button is some code to perform the actual update. The relevant part of this code is:

row["Date01"] = (DateTime)newAmendDate;
var success = oTrans.Update();
oTrans.NotifyAll(true);

As you can see its very simple and nothing complex, however in some circumstances which are outlined below, the Update() method will reset the value of the row and it will not be saved to the database. I have tried using BeginEdit() and EndEdit() as well but to no avail.

Circumstances:

This works:

  1. Load PO
  2. Select Line
  3. Modify PO Amend Date
  4. Make another change
  5. Save Form
  6. Select New Line
  7. Modify PO Amend Date

This method will make all changes as expected to the Database.

This does not work:

  1. Load PO
  2. Select Line
  3. Modify PO Amend Date
  4. Select Another Line
  5. Modify PO Amend Date – This one fails.

I cant ask users to Save the form between lines without changing anything else as there is no binding on the field as it is all done in the code, it doesnt recognise a change and therefore Update() will not be triggered.

I am really stumped by this and have lost many hours on it. If anybody knows what may cause this I will be forever grateful.

Thanks.

P.S. Epicor version 10.1.500

Hi Daniel,

are you not using Epicor binding? if not paste your code here to see what wrong your doing.

Hi,

No i am not using epicor binding. I was not the original developer behind this so cannot explain the reason why. The full code for what happens on button click is as follows:

var edvPORel = (EpiDataView)oTrans.EpiDataViews["PORel"];
var row = edvPORel.CurrentDataRow;
if (newAmendDate != null && reason != "")
{
    try
    {
    var callContext = (EpiDataView)oTrans.EpiDataViews["CallContextClientData"];
    var userName = callContext.dataView[callContext.Row]["CurrentUserId"];
						
    var poNum = row["PONum"];
    var poLine = row["POLine"];
    var poRel = row["PORelNum"];
    var oldAmendDate = row["Date01"];
    row["Date01"] = (DateTime)newAmendDate;
    var success = oTrans.Update();
    oTrans.NotifyAll(true);
			
    using (SqlConnection connection = new SqlConnection(CONNECTION_STRING))
    {
        string qry = @"INSERT INTO nexus_po_date_log (PONum, POLine, PORelNum, OldDate, NewDate, Reason, Username) 
	    VALUES (@poNum, @poLine, @poRel, @oldDate, @newDate, @reason, @username)";
	    SqlCommand cmd = new SqlCommand(qry, connection);
	    cmd.Parameters.AddWithValue("@poNum", poNum);
	    cmd.Parameters.AddWithValue("@poLine", poLine);
	    cmd.Parameters.AddWithValue("@poRel", poRel);
	    cmd.Parameters.AddWithValue("@oldDate", oldAmendDate);
	    cmd.Parameters.AddWithValue("@newDate", newAmendDate);
	    cmd.Parameters.AddWithValue("@reason", reason);
	    cmd.Parameters.AddWithValue("@username", userName);
				
	    cmd.Connection.Open();
	    cmd.ExecuteNonQuery();
	}					
}
catch (Exception ex)
{
    throw ex;
}
} 
else 
{
    MessageBox.Show("Please select a date and provide a reason for change.");
}

The majority of this is purely logging which happens after the fact but I hope this shows everything you need.

Try using beginedit and endedit to alert the form of the change

-Jose

I did try as below but Im not sure if im using it correct. Also tried using SetModified() and AcceptChanges()

row.BeginEdit();
row["Date01"] = (DateTime)newAmendDate;
row.EndEdit();
row.AcceptChanges();
row.SetModified();
var success = oTrans.Update();
oTrans.NotifyAll(true);

Oh yikes!
You are writing to a sql db … And directly from the UI :scream::scream::scream:
Hmm try setting the rowmod if the row

1 Like

If i add in row.RowMod = “U”; i get the error:

'System.Data.DataRow' does not contain a definition for 'RowMod' and no extension method 'RowMod' accepting a first argument of type 'System.Data.DataRow' could be found (are you missing a using directive or an assembly reference?)

RowMod is just another field you need to quote it

1 Like

OK using:
row["RowMod"] = "U";

it compiles fine now however, the issue still persists

follow these steps

  1. add update your code Initialize

    private EpiDataView _edvPORel;
    

    public void InitializeCustomCode()
    {
    // ** Wizard Insert Location - Do not delete ‘Begin/End Wizard Added Variable Initialization’ lines **
    // Begin Wizard Added Variable Initialization

     // End Wizard Added Variable Initialization
     this._edvPORel = ((EpiDataView)(this.oTrans.EpiDataViews["PORel"]));
     // Begin Wizard Added Custom Method Calls
    
     // End Wizard Added Custom Method Calls
    

    }

  2. public void DestroyCustomCode()
    

    {
    // ** Wizard Insert Location - Do not delete ‘Begin/End Wizard Added Object Disposal’ lines **
    // Begin Wizard Added Object Disposal

     // End Wizard Added Object Disposal
     this._edvPORel = null;
     // Begin Custom Code Disposal
    
     // End Custom Code Disposal
    

    }

3 var edvPORel = (EpiDataView)oTrans.EpiDataViews[“PORel”];
var row = edvPORel.CurrentDataRow;
if (newAmendDate != null && reason != “”)
{
try
{
var callContext = (EpiDataView)oTrans.EpiDataViews[“CallContextClientData”];
var userName = callContext.dataView[callContext.Row][“CurrentUserId”];

var poNum = row["PONum"];
var poLine = row["POLine"];
var poRel = row["PORelNum"];
var oldAmendDate = row["Date01"];
DataRow editRow = this._edvPORel.CurrentDataRow;;
editRow.BeginEdit();
editRow["Date01"] = (DateTime)dt_AmendDate.Value;
editRow.EndEdit();
this.oTrans.Update();
this._edvPORel.Notify(new EpiNotifyArgs(this.oTrans, this._edvPORel.Row, this._edvPORel.Column));
		
using (SqlConnection connection = new SqlConnection(CONNECTION_STRING))
{
    string qry = @"INSERT INTO nexus_po_date_log (PONum, POLine, PORelNum, OldDate, NewDate, Reason, Username) 
    VALUES (@poNum, @poLine, @poRel, @oldDate, @newDate, @reason, @username)";
    SqlCommand cmd = new SqlCommand(qry, connection);
    cmd.Parameters.AddWithValue("@poNum", poNum);
    cmd.Parameters.AddWithValue("@poLine", poLine);
    cmd.Parameters.AddWithValue("@poRel", poRel);
    cmd.Parameters.AddWithValue("@oldDate", oldAmendDate);
    cmd.Parameters.AddWithValue("@newDate", newAmendDate);
    cmd.Parameters.AddWithValue("@reason", reason);
    cmd.Parameters.AddWithValue("@username", userName);
			
    cmd.Connection.Open();
    cmd.ExecuteNonQuery();
}					

}
catch (Exception ex)
{
throw ex;
}
}
else
{
MessageBox.Show(“Please select a date and provide a reason for change.”);
}

PS let me know if you have any question

Unfortunately updating my code as you described didnt work. I had to make slight changes as its a static class. Could the static class be the issue? Im not sure if it needs to be static or not and if not im not sure why it was created as static

Hi Daniel,

I am not sure why and how this code created. if you have any documentation share to get more idea or ping me on Skype surendrpal to review your code.

Thanks
Surendra Pal

@daroga please Mark this as solution and post final solution as we discussed on skype for others help in future

1 Like

I’m looking over this post to see if it can help me with a project. I see exactly how it is working. I have a Dashboard with a Tracker View and a button on it. I want to save and update the record even without changing a field. The save at the top needs a field change first. I’ve tried using oTrans.Update() but haven’t gotten it correct. I read another post that said it didn’t work on Tracker Views for them.

I put in a message so the button works and I commented out the Update. I’ve used several variations that I found but I don’t see how they are working.

private static void epiButton1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

MessageBox.Show(“Test Button”);
//oTrans.Update();
//oTrans.Refresh();
}

I’m not sure how helpful this brief response will be but I recently had to save a record on a tracker (attachments). To do it, I had to grab the Adapter from the Form’s Transaction object using reflection. From there, it’s like using an adapter the standard way.

Any documentation you are following?

Oh no, this is definitely outside the scope of approved actions lol. You arent supposed to be able update a Tracker.

I actually may have misinterpreted. I thought we were talking about a tracker (like SalesOrderTracker, etc). Sounds like you are talking about a dashboard tracker.

Yes it is a Dashboard Tracker.

I’m still looking for the object and code to save a record in the tracker from a button. Anyone have any suggestions to try?