Acumatica - Unposted Journal transactions - c#

I programmatically create a credit memo and then i release by ARDocumentRelease.ReleaseDoc(rebateRelease, false); and i got this error.
{"Error: Another process has updated the 'ARRegister' record. Your changes will be lost."}.
The effect of this error is in the journal transaction, the created journal transaction is having a unposted status. Please check the images thanks.
Unposted Journal Transaction, Closed Credit Memo, Error in code, Suggestion 1
MY CODE BELOW:
`ARInvoice arInvoice = new ARInvoice();
arInvoice.DocType = "CRM";
arInvoice.CustomerID = loan.BAccountID;
arInvoice.CustomerLocationID = loan.CustomerLocation;
arInvoice.DocDesc = "";
arInvoice.OpenDoc = true;
arInvoice.Released = false;
arInvoice.Hold = false;
arInvoice.Status = "B";
if (arSetup.RequireControlTotal == true)
{
arInvoice.CuryOrigDocAmt = amount;
}
arInvoice = ARGraph.Document.Update(arInvoice);
ARGraph.Actions.PressSave();
ARTran arTran = new ARTran();
arTran.RefNbr = arInvoice.RefNbr;
arTran.LineNbr = 1;
arTran.SortOrder = 1;
arTran.TranDesc = description;
arTran.AccountID = accountID;
arTran.SubID = subID;
arTran.Qty = 1;
arTran.TaxCategoryID = other.TaxCategoryID;
arTran.CuryExtPrice = amount;
arTran.Released = false;
ARGraph.Transactions.Insert(arTran);
ARGraph.Actions.PressSave();
rebateRelease.Add(arInvoice);
ARDocumentRelease.ReleaseDoc(rebateRelease, false);`

Try to change the last few lines to this...
rebateRelease.Add(ARGraph.Document.Current);
ARDocumentRelease.ReleaseDoc(rebateRelease, false);
My guess your issue is that you saved the graph which updated your arInvoice record and you are still using the old arInvoice record through that object. You need the updated value after you did the press save.
Also to save some overhead you can just save once before you send the doc to release. No need to save after the ARGraph.Document.Update(arInvoice) line.

Related

Problem with modifying an MSI database property

I need to modify the UpgradeCode property of the Upgrade MSI table via C#.
This code works ok with other tables' properties, but throws an error when I'm trying to modify these.
using (var database = new Database(TEMPDATABASE, DatabaseOpenMode.Direct))
{
string upgradeCode = Guid.NewGuid().ToString("B").ToUpper();
database.Execute("Update `Upgrade` Set `Upgrade`.`UpgradeCode` = '{0}'", upgradeCode);
}
The error is:
Microsoft.Deployment.WindowsInstaller.InstallerException: 'Function failed during execution.'
I got curious and pillaged github.com - and it giveth the following: Full project - just download it as a whole.
The actual code was (some unicode line feed issues in the file on github.com, I have fixed them up here):
public static void UpdateUpgradeTable(this Database db, Guid upgradeCode)
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = upgradeCode.ToString("B").ToUpperInvariant();
view.Replace(record);
}
db.Commit();
}
}
I took the above and made the following mock-up (very ugly, but it worked):
using (Database db = new Database(#"C:\Test.msi", DatabaseOpenMode.Direct))
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "4.0.1";
record[4] = "";
record[5] = "1";
record[6] = "";
record[7] = "WIX_UPGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "";
record[4] = "4.0.1";
record[5] = "1";
record[6] = "";
record[7] = "WIX_DOWNGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
}
}
The SDK doc says:
UPDATE queries only work on nonprimary key columns.
UpgradeCode is the primary key for the Upgrade table.

C# Excel Drop Down List

I am trying to create a drop list, haven't had any luck finding similar sample code or documentation to follow so I'm flying solo
When I run this sample code I created
static void Main(string[] args)
{
using (FileStream filename = new FileStream(#"INSERTYOUROWNPATH.xlsx", FileMode.Create))
{
var workbook = new XSSFWorkbook();
XSSFSheet xsheet = (XSSFSheet)workbook.CreateSheet("Validation");
CT_DataValidation valid = new CT_DataValidation();
valid.showDropDown = true;
valid.allowBlank = true;
var constraint = new XSSFDataValidationConstraint(new string[] { "0064", "0061" }); //to be used in list
var range = new CellRangeAddressList(11, 14, 13, 13); //apply to row 12:14 starting at column N finishing at column N
var addingconstraint = new XSSFDataValidation(constraint, range, valid);
addingconstraint.EmptyCellAllowed = true;
addingconstraint.SuppressDropDownArrow = false;
xsheet.AddValidationData(addingconstraint);
workbook.Write(filename);
}
}
I get the following errors when I open the spreadsheet:
"We found a problem with some content in "Validations.xlsx" do you
want use to try to recover as much as we can? If you trust the source
of this workbook, click Yes"
Then I get the following repair message:
"Repaired Part: /xl/worksheets/sheet1.xml part with XML error. Load
error. Line 1 column 684"
Could I please get some insight in to where this is failing?
your issue seems to be very similar to this problem about data validation and data constraint.
XSSFDataValidation dataValidation = null;
XSSFDataValidationConstraint dvConstraint = null;
XSSFDataValidationHelper validationHelper = null;
int DVRowLimit = (Int16.MaxValue);
XSSFCellStyle numberCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
XSSFDataFormat numberDataFormat = (XSSFDataFormat)workbook.CreateDataFormat();
numberCellStyle.SetDataFormat(numberDataFormat.GetFormat("#,###,###"));
CellRangeAddressList cellRangeFieldsType1 = new CellRangeAddressList(1, DVRowLimit, headerCount, headerCount);
dvConstraint = (XSSFDataValidationConstraint)validationHelper.CreateintConstraint(OperatorType.BETWEEN, "0", Int64.MaxValue.ToString());
dataValidation = (XSSFDataValidation)validationHelper.CreateValidation(dvConstraint, cellRangeFieldsType1);
dataValidation.ShowErrorBox = true;
dataValidation.SuppressDropDownArrow = true;
dataValidation.ErrorStyle = 0;
dataValidation.CreateErrorBox("InvalidValue", "Number Should be a integer.");
dataValidation.ShowErrorBox = true;
dataValidation.CreatePromptBox("Number Data Validation", "Enter Number.");
dataValidation.ShowPromptBox = true;
sheet.AddValidationData(dataValidation);
sheet.SetDefaultColumnStyle(column, numberCellStyle);

DataSet Saving Changes

I have a Visual Studio C# Forms project. In that project is SmartCon.mdf. As you can see below the DataSet is created.
For some reason the data is not saving. When I add a player to the dataset my code is as follows.
SmartConDataSet.PlayersRow newPlayer = myData.Players.NewPlayersRow();
newPlayer.Id = Guid.NewGuid().ToString();
newPlayer.Guid = newGuid;
newPlayer.FirstSeen = DateTime.Now;
newPlayer.Kills = 0;
newPlayer.Deaths = 0;
newPlayer.TotalScore = 0;
myData.Players.AddPlayersRow(newPlayer);
SmartConDataSet.NamesRow newName = myData.Names.NewNamesRow();
newName.Id = Guid.NewGuid().ToString();
newName.Name = Name;
newName.PlayerId = newPlayer.Guid;
newName.Active = 1;
myData.Names.AddNamesRow(newName);
//Update the database
myData.AcceptChanges();
Why isn't my data saving to the database?
UPDATE:
I can confirm the data is getting added to the DataSet, but not transfering to the Database.
UPDATE 2: I may need a connection string to the database????
UPDATE 3:
var playerTableAdapter = new SmartConDataSetTableAdapters.PlayersTableAdapter();
SmartConDataSet.PlayersRow newPlayer = myData.Players.NewPlayersRow();
newPlayer.Id = Guid.NewGuid().ToString();
newPlayer.Guid = newGuid;
newPlayer.FirstSeen = DateTime.Now;
newPlayer.Kills = 0;
newPlayer.Deaths = 0;
newPlayer.TotalScore = 0;
playerTableAdapter.Insert(newPlayer.Guid, newPlayer.Kills, newPlayer.Deaths, newPlayer.Id, newPlayer.FirstSeen, newPlayer.FirstSeen, 0);
//Add the players name to the name table
var namesTableAdapter = new SmartConDataSetTableAdapters.NamesTableAdapter();
SmartConDataSet.NamesRow newName = myData.Names.NewNamesRow();
newName.Id = Guid.NewGuid().ToString();
newName.Name = Name;
newName.PlayerId = newPlayer.Id;
newName.Active = 1;
var result = namesTableAdapter.Insert(newName.Id, newName.PlayerId, newName.Name, 1);
From my research, a DataSet cannot directly make changed to the database. See this thread...
Does instantiating a DataSet object automatically create a connection to a SQL service-based database for CRUD operations?
However my database is still not being updated with the new rows.
UPDATE 4:
According to the link in update 3, the connection string was wrong as well. everything works great, HOWEVER, My connection string is now a path on my computer rather than a relative path. If I place this on someone else computer it wont work as their file path will not be the same as mine.
The database is not updated using these methods. you need to use TableAdapter.Insert Update etc

How to update CreatedFrom of Journal Entry by SuiteTalk?

I have to apply/attach a Journal Entry to the VendorPayment for voiding, so that I've tried 2 ways:
First is update the (RecordRef)createdFrom of Journal Entry = (recordRef)vendorPayment
Here is my code:
RecordRef vPaymentRef = new RecordRef();
vPaymentRef.internalId = "7850";
vPaymentRef.type = RecordType.vendorPayment;
vPaymentRef.typeSpecified = true;
RecordRef currency = new RecordRef();
currency.internalId = "1";
currency.type = RecordType.currency;
RecordRef mySubsidiary = new RecordRef();
mySubsidiary.internalId = "3";
mySubsidiary.type = RecordType.subsidiary;
JournalEntry newJournalEntry = new JournalEntry();
newJournalEntry.subsidiary = mySubsidiary;
newJournalEntry.createdFrom = vPaymentRef;
//newJournalEntry.reversalEntry = "99";
newJournalEntry.reversalDate = DateTime.Now;
newJournalEntry.reversalDateSpecified = true;
//newJournalEntry.reversalDefer = true;
//newJournalEntry.reversalDeferSpecified = true;
RecordRef myCurrency = new RecordRef();
myCurrency.internalId = "1";
newJournalEntry.currency = myCurrency;
newJournalEntry.exchangeRate = .911;
newJournalEntry.exchangeRateSpecified = true;
RecordRef myDebitAccount = new RecordRef();
myDebitAccount.internalId = "290"; //account
RecordRef myCreditAccount = new RecordRef();
myCreditAccount.internalId = "25"; //a/p account
newJournalEntry.lineList = new JournalEntryLineList();
newJournalEntry.lineList.line = new JournalEntryLine[2];
newJournalEntry.lineList.line[0] = new JournalEntryLine();
newJournalEntry.lineList.line[0].account = myDebitAccount;
newJournalEntry.lineList.line[0].debit = 3333;
newJournalEntry.lineList.line[0].debitSpecified = true;
newJournalEntry.lineList.line[0].entity = vPayment.entity;
newJournalEntry.lineList.line[1] = new JournalEntryLine();
newJournalEntry.lineList.line[1].account = myCreditAccount;
newJournalEntry.lineList.line[1].credit = 3333;
newJournalEntry.lineList.line[1].creditSpecified = true;
newJournalEntry.lineList.line[1].entity = vPayment.entity;
WriteResponse wr = _service.add(newJournalEntry);
As you see, I have added a VendorPayment to CreatedFrom, the WriteResponse status return true with StatusDetail = null. But when I access the Journal Entry have just created on Netsuite site, the VOID OF is empty (not display). And the type of Journal Entry is "Journal", It have to be "Voiding Journal", and don't have "Reversal Payments Applied" beside the Entry No.
Then, I try the second way : Update the voidJournal of VendorPayment to use the Journal Entry have just created.
Here is my code :
RecordRef recordRef = new RecordRef();
recordRef.internalId = "7850";
recordRef.type = RecordType.vendorPayment;
recordRef.typeSpecified = true;
ReadResponse response2 = _service.get(recordRef);
VendorPayment vPayment = (VendorPayment)response2.record;
RecordRef recordRefJournal = new RecordRef();
recordRefJournal.internalId = "8356";
recordRefJournal.type = RecordType.journalEntry;
recordRefJournal.typeSpecified = true;
vPayment.voidJournal = recordRefJournal;
vPayment.status = "VOIDED";
WriteResponse wr2 = _service.update(vPayment);
With this way, the WriteResponse status still true, and the StatusDetail still null. When I refresh this vendorPayment on Netsuite site, nothing change, the VOIDED ON and the Status not change.
My Point is Voiding the VendorPayment by SuiteTalk.
I'm really stuck here, please help. Many thanks !!
Create From field is a field that can only be set by the system. It will only be populate when transforming transactions.
Created From field of the Invoice will only be populated when you click the Bill button of the sales order and another scenario is when you click the Receive button on the PO the Created From field of the Item Receipt.
In suitescirpt
nlapiTransformRecord('salesorder', 1, 'invoice');
What you are trying to do is not possible using the standard Created From field.
Indeed, the previous comment is right.
What you need to do is two step:
Create the journal entry and reference the Vendor in the entity lines.
Apply it as a payment against the bill.
Consider the code pattern to the article I wrote about writing off Customer Invoices with a Journal Entry.
Marty Zigman, Founder
Prolecto Resources, Inc.
NetSuite Systems Integration
Southern California's Leading Innovation and Implementation Practice

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. Visual C# 2010

i'm sorry. i wouldn't post this if i weren't out of ideas. i've tried everything in the forums, but to no avail.
so i have 2 tables. both are empty at the beginning. the first table is kind of like a customer masterlist where the user creates a new customer profile. here is the code:
con.Open();
System.Data.SqlClient.SqlCommandBuilder cb;
System.Data.SqlClient.SqlCommandBuilder readingcb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
readingcb = new System.Data.SqlClient.SqlCommandBuilder(readingda);
DataRow dRow = custMaster.Tables["custMaster"].NewRow();
DataRow readingdRow = reading.Tables["reading"].NewRow();
dRow[1] = a_newCust.Text;
readingdRow[9] = a_newCust.Text;
dRow[2] = b_newCust.Text;
readingdRow[10] = b_newCust.Text;
dRow[3] = c_newCust.Text;
readingdRow[11] = c_newCust.Text;
dRow[4] = d_newCust.Text;
readingdRow[0] = d_newCust.Text;
dRow[5] = e_newCust.Text.ToString();
readingdRow[2] = e_newCust.Text.ToString();
dRow[6] = f_newCust.Text;
readingdRow[1] = f_newCust.Text;
dRow[7] = g_newCust.Text.ToString();
if (radioButton1.Checked == true)
{
dRow[8] = radioButton1.Text;
readingdRow[3] = radioButton1.Text;
}
else if (radioButton2.Checked == true)
{
dRow[8] = radioButton2.Text;
readingdRow[3] = radioButton2.Text;
}
dRow[9] = "Active";
readingdRow[12] = "Active";
readingdRow[4] = 0;
readingdRow[5] = 0;
custMaster.Tables["custMaster"].Rows.Add(dRow);
reading.Tables["reading"].Rows.Add(readingdRow);
MaxRows = MaxRows + 1;
readingMaxRows = readingMaxRows + 1;
inc = MaxRows - 1;
readinginc = readingMaxRows - 1;
this.da.Update(custMaster, "custMaster");
this.readingda.Update(reading, "reading");
da.Fill(masterDataSet3.custMaster);
readingda.Fill(streetDataSet.reading);
masterfileGrid.Invalidate();
readingGrid.Invalidate();
masterfileGrid.Refresh();
readingGrid.Refresh();
MessageBox.Show("Customer succesfully added!");
con.Close();
when this part completes, my program will create a new record in the "custMaster" table, and also a new record in the "reading" table (but this record still has some null fields). when the user goes to the "reading" table, he sees the new record, and then updates that record by adding some column values (thereby filling in the null fields). here is the code:
con.Open();
System.Data.SqlClient.SqlCommandBuilder readingup;
System.Data.SqlClient.SqlCommandBuilder custpayadd;
readingup = new System.Data.SqlClient.SqlCommandBuilder(readingda);
custpayadd = new System.Data.SqlClient.SqlCommandBuilder(custpayda);
int test = int.Parse(f_reading.Text);
int prev = int.Parse(readingNinBox.Text);
DataRow readingdRow = reading.Tables["reading"].Rows[test-1];
readingdRow[4] = prev;
readingdRow[5] = int.Parse(d_reading.Text);
readingdRow[13] = e_reading.Value.ToShortDateString();
readingdRow[6] = int.Parse(d_reading.Text) - prev;
if (g_reading.Text == "Residential")
{
DataRow resSearchdRow = water.Tables["water"].Rows[int.Parse(d_reading.Text) - prev];
readingdRow[7] = resSearchdRow[2];
}
else
{
DataRow commSearchdRow = commWater.Tables["commWater"].Rows[int.Parse(d_reading.Text) - prev];
readingdRow[7] = commSearchdRow[2];
}
this.readingda.Update(reading, "reading"); //>>>>>>>>>>this part is where i get the concurrency error.
readingda.Fill(streetDataSet.reading);
readingGrid.Invalidate();
readingGrid.Refresh();
//elsewhere:
masterDataSet reading;
System.Data.SqlClient.SqlDataAdapter readingda;
int readingMaxRows = 0;
int readinginc = 0;
this.readingTableAdapter.Fill(this.streetDataSet.reading);
reading = new masterDataSet();
string readingsql = "SELECT * From reading";
readingda = new System.Data.SqlClient.SqlDataAdapter(readingsql, con);
readingda.Fill(reading, "reading");
readingMaxRows = reading.Tables["reading"].Rows.Count;
readingda.Update(reading, "reading");
i don't understand why i get this, since i use the same lines of updating codes in my other forms but they work well. any help would be greatly appreciated. thanks.
Some additional information: i only get the error the first time a record is added to the "reading" table. when i close and reopen my program, i can update the record fine.
i have the same problem. but i am using Visual studio 2010 with C# and windows form. i solved my problem by placing "this.contactDBDataSet.AcceptChanges(); before "this.tableAdapterManager.UpdateAll(this.contactDBDataSet);". here is the sample.
private void peopleBindingNavigatorSaveItem_Click_2(object sender, EventArgs e)
{
this.Validate();
this.peopleBindingSource.EndEdit();
this.contactDBDataSet.AcceptChanges();// added by Humayoo
this.tableAdapterManager.UpdateAll(this.contactDBDataSet);
}
this.contactDBDataSet.AcceptChanges();
That Right !! FIN
I received this error message because my workstation was set to a different time zone than my server. Once I got it back to the same time zone...problem went away
This error is mostly because of updating multiple changes to database without reloading updated data between requests and when you try to save(Update) stacked changes this error may occur.
For more info check this answer by Henk which was very helpful for me.
And here there is a good example in details.
I know this thread is old, but I'd like to share the situation in which I got this error in case anyone runs across this also from an internet search.
I was seeing this error message in a legacy app. It turned out to be a result of a previous programmer coding up some logic that retrieved a DataTable, forcibly removed a column from it, then allowed the user to edit the DataTable in a grid. The DataTable was then passed to the adapter (an OracleDataAdapter in my case) to apply any changes.
So...manually removing a column from a DataTable before sending it to the SqlDataAdapter can also result in this error message.

Categories