Hi
I trying to create AR invoices from a excel file with no luck. Im getting "null reference exception - Object reference not set to an instance of an object." on the line: ARINVOICE1headerFields.FieldByName("INVCTYPE").SetValue("2", false); // ' Invoice Type
Please advice
private void GenerateArInvoice(DataSet ds, OleDbConnection con)
{
session = new ACCPAC.Advantage.Session();
session.Init("", "XX", "XX1000", "55A");
session.Open("ADMIN", "ADMIN", "SAMINC", DateTime.Today, 0);
mDBLinkCmpRW = session.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
OpenAndComposeOrderViews();
//criacao do batch
//ARINVOICE1batch.RecordCreate(1);
ARINVOICE1batch.Init();
ARINVOICE1batchFields.FieldByName("BTCHDESC").SetValue("Generated from Softship File on " + DateTime.Now,true) ; //Description
ARINVOICE1batchFields.FieldByName("DATEBTCH").SetValue (DateTime.Now,true);
ARINVOICE1batch.Update();
foreach (DataRow dr in ds.Tables[0].Rows)
{
ARINVOICE1header.Init();
ARINVOICE1header.RecordGenerate(false);
ARINVOICE1headerFields.FieldByName("INVCTYPE").SetValue("2", false); // ' Invoice Type
ARINVOICE1headerFields.FieldByName("IDCUST").SetValue(dr["CUSTOMER"].ToString(),true); // Trim(scsv.Cells(i, 1)) 'Customer Number
ARINVOICE1headerFields.FieldByName("INVCDESC").SetValue(dr["ENTRY DESCRIPTION"].ToString(), false); // Trim(scsv.Cells(i, 2)) ' Invoice Description
ARINVOICE1headerFields.FieldByName("TEXTTRX").SetValue(dr["DOCUMENT TYPE"].ToString(), false); // Trim(scsv.Cells(i, 3)) ' Document Type
ARINVOICE1headerFields.FieldByName("INCAPPLTO").SetValue(dr["APPLY TO"].ToString(), false); // Trim(scsv.Cells(i, 4)) ' Apply-to Document
ARINVOICE1headerFields.FieldByName("IDINVC").SetValue(dr["DOCID"].ToString(), false); // Trim(scsv.Cells(i, 5)) ' Document Number
ARINVOICE1headerFields.FieldByName("ORDRNBR").SetValue(dr["ORDER NUMBER"].ToString(), false); // Trim(scsv.Cells(i, 6)) ' Order Number
ARINVOICE1headerFields.FieldByName("DATEINVC").SetValue(DateTime.Parse(dr["DOCUMENT DATE"].ToString().Replace(".","//")),false); // DateSerial(Year, Month, Day)
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [Sheet1$] WHERE [DOCUMENT NUMBER]='" + dr["DOCID"].ToString() + "' AND [CUSTOMER]='" + dr["CUSTOMER"].ToString() + "'", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "ExcelInfo1");
if (ds1.Tables[0].Rows.Count > 0)
{
double vAmt=0;
foreach (DataRow dr1 in ds1.Tables[0].Rows)
{
ARINVOICE1detail1.Init();
ARINVOICE1detail1Fields.FieldByName("IDACCTREV").SetValue(dr1["REVENUE ACCOUNT"].ToString(),true); // = Trim(scsv.Cells(i, 9)) ' Revenue Account
vAmt = double.Parse(dr1["AMOUNT"].ToString())* double.Parse(dr1["RATE"].ToString());// Trim(scsv.Cells(i, 11))
ARINVOICE1detail1Fields.FieldByName("AMTEXTN").SetValue(vAmt,true) ; // ' Extended Amount w/ TIP
ARINVOICE1detail1.Insert();
}
}
ARINVOICE1headerFields.FieldByName("EXCHRATEHC").SetValue(dr["RATE"].ToString(),false);
ARINVOICE1header.Insert();
}
Cleanup();
}
I trying to create AR invoices from a excel file with no luck. Im getting "null reference exception - Object reference not set to an instance of an object." on the line: ARINVOICE1headerFields.FieldByName("INVCTYPE").SetValue("2", false); // ' Invoice Type
Please advice
private void GenerateArInvoice(DataSet ds, OleDbConnection con)
{
session = new ACCPAC.Advantage.Session();
session.Init("", "XX", "XX1000", "55A");
session.Open("ADMIN", "ADMIN", "SAMINC", DateTime.Today, 0);
mDBLinkCmpRW = session.OpenDBLink(ACCPAC.Advantage.DBLinkType.Company, ACCPAC.Advantage.DBLinkFlags.ReadWrite);
OpenAndComposeOrderViews();
//criacao do batch
//ARINVOICE1batch.RecordCreate(1);
ARINVOICE1batch.Init();
ARINVOICE1batchFields.FieldByName("BTCHDESC").SetValue("Generated from Softship File on " + DateTime.Now,true) ; //Description
ARINVOICE1batchFields.FieldByName("DATEBTCH").SetValue (DateTime.Now,true);
ARINVOICE1batch.Update();
foreach (DataRow dr in ds.Tables[0].Rows)
{
ARINVOICE1header.Init();
ARINVOICE1header.RecordGenerate(false);
ARINVOICE1headerFields.FieldByName("INVCTYPE").SetValue("2", false); // ' Invoice Type
ARINVOICE1headerFields.FieldByName("IDCUST").SetValue(dr["CUSTOMER"].ToString(),true); // Trim(scsv.Cells(i, 1)) 'Customer Number
ARINVOICE1headerFields.FieldByName("INVCDESC").SetValue(dr["ENTRY DESCRIPTION"].ToString(), false); // Trim(scsv.Cells(i, 2)) ' Invoice Description
ARINVOICE1headerFields.FieldByName("TEXTTRX").SetValue(dr["DOCUMENT TYPE"].ToString(), false); // Trim(scsv.Cells(i, 3)) ' Document Type
ARINVOICE1headerFields.FieldByName("INCAPPLTO").SetValue(dr["APPLY TO"].ToString(), false); // Trim(scsv.Cells(i, 4)) ' Apply-to Document
ARINVOICE1headerFields.FieldByName("IDINVC").SetValue(dr["DOCID"].ToString(), false); // Trim(scsv.Cells(i, 5)) ' Document Number
ARINVOICE1headerFields.FieldByName("ORDRNBR").SetValue(dr["ORDER NUMBER"].ToString(), false); // Trim(scsv.Cells(i, 6)) ' Order Number
ARINVOICE1headerFields.FieldByName("DATEINVC").SetValue(DateTime.Parse(dr["DOCUMENT DATE"].ToString().Replace(".","//")),false); // DateSerial(Year, Month, Day)
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT * FROM [Sheet1$] WHERE [DOCUMENT NUMBER]='" + dr["DOCID"].ToString() + "' AND [CUSTOMER]='" + dr["CUSTOMER"].ToString() + "'", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "ExcelInfo1");
if (ds1.Tables[0].Rows.Count > 0)
{
double vAmt=0;
foreach (DataRow dr1 in ds1.Tables[0].Rows)
{
ARINVOICE1detail1.Init();
ARINVOICE1detail1Fields.FieldByName("IDACCTREV").SetValue(dr1["REVENUE ACCOUNT"].ToString(),true); // = Trim(scsv.Cells(i, 9)) ' Revenue Account
vAmt = double.Parse(dr1["AMOUNT"].ToString())* double.Parse(dr1["RATE"].ToString());// Trim(scsv.Cells(i, 11))
ARINVOICE1detail1Fields.FieldByName("AMTEXTN").SetValue(vAmt,true) ; // ' Extended Amount w/ TIP
ARINVOICE1detail1.Insert();
}
}
ARINVOICE1headerFields.FieldByName("EXCHRATEHC").SetValue(dr["RATE"].ToString(),false);
ARINVOICE1header.Insert();
}
Cleanup();
}