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:
Load PO
Select Line
Modify PO Amend Date
Make another change
Save Form
Select New Line
Modify PO Amend Date
This method will make all changes as expected to the Database.
This does not work:
Load PO
Select Line
Modify PO Amend Date
Select Another Line
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.
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.
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?)
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
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 **
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.
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.