By Steve Endow
I just posted a story about how I discovered that sometimes I need to explicitly create Dynamics GP batches using eConnect in order to control the batch posting date.
Here's the code that I used.
First, I check to see if the batch exists.
public static bool BatchExists(string database, int series, string batchSource, string batchID)
{
try
{
string commandText = "SELECT COUNT(*) AS RecordCount FROM dbo.SY00500 WHERE SERIES = @SERIES AND BCHSOURC = @BCHSOURC AND BACHNUMB = @BACHNUMB"; // AND GLPOSTDT = @GLPOSTDT";
SqlParameter[] sqlParameters = new SqlParameter[3];
sqlParameters[0] = new SqlParameter("@SERIES", System.Data.SqlDbType.Int);
sqlParameters[0].Value = series;
sqlParameters[1] = new SqlParameter("@BCHSOURC", System.Data.SqlDbType.VarChar, 15);
sqlParameters[1].Value = batchSource.Trim();
sqlParameters[2] = new SqlParameter("@BACHNUMB", System.Data.SqlDbType.VarChar, 15);
sqlParameters[2].Value = batchID.Trim();
string result = DataAccess.ExecuteScalar(database, CommandType.Text, commandText, sqlParameters);
int recordCount = Convert.ToInt32(result);
if (recordCount > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Log.Write("An unexpected error occurred in DataAccess.BatchExists: " + ex.Message, true);
return false;
}
}
If the batch does exist, I make sure to update the posting date.