Update sales order with third party tax info. - Tax regulation error

Hi,

I am writing a program that sends ecommerce orders from our website to AX and I am running into trouble with updating the sales tax. We are using a third party site to get our tax rates and I need to be able to update the rates AX generated for that order.I can get the adjustment to show in the Sales Tax Form on the sales order but I still can’t process it.

the closest I’ve come is using the code below:

// This is the only method in the ImportToAX Class
str ImportSalesOrder (str CustAccount, str _oppNo,SalesPrice MinPmtAmt)
{

SalesLine salesLine;
InventDim inventDim;
NumberSeq NumberSeq;

TaxWorkRegulation taxWorkRegulation;
;

retval = “”;

try
{

// Obtain the next SalesId (Next Number Sequence)…

NumberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
salesTable.SalesId = NumberSeq.num();

// Create the Sales Order…

salesTable.initValue();
salesTable.CustAccount = CustAccount;
salesTable.PurchOrderFormNum = _oppNo;
salesTable.SalesResponsible = “CADMIN”;
salesTable.initFromCustTable();
salesTable.insert();

// Create the Sales Line…

salesLine.clear();
salesLine.SalesId = salesTable.SalesId;

// The following three lines were added, because AX was requiring a defined site for inventory dimensions…
inventDim = salesLine.inventDim();
inventDim.InventSiteId = “001”;
salesLine.setInventDimIdFromInventDim(inventDim);

// Item information
salesLine.ItemId = ‘MMP’;
salesLine.SalesPrice = MinPmtAmt;
salesLine.LineAmount = MinPmtAmt;
salesLine.SalesQty = 1;
salesLine.QtyOrdered = 1;
salesLine.SalesUnit = ‘EA’;
salesLine.TaxItemGroup = ‘ALL’;

// Create the Sales Order Line
salesLine.createLine(NoYes::Yes, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::No, NoYes::No);

////////////////// Test code for sales tax adjustment
taxWorkRegulation.HeadingRecId=salesTable.RecId;
taxWorkRegulation.HeadingTableId=salesTable.TableId;
taxWorkRegulation.TaxDirection= TaxDirection::OutgoingTax;
taxWorkRegulation.TaxRegulationAmountCur = -987;
taxWorkRegulation.TaxCode=‘AKUY’;
taxWorkRegulation.insert();
//////////////////////

retval = salesTable.SalesId;
}
catch
{
retval = “”;
}

return retval;
}

SalesFormLetter CreateInvoice(TransDate MinDate)
{

SalesFormLetter letter=SalesFormLetter::construct(DocumentStatus::Invoice);
;

// Create the Invoice

ttsBegin;
letter.update(salesTable, MinDate, SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::No);
ret = letter;
ttsCommit;

return ret;
}

I still get the following error:

Tax is regulated on sales order ID S24601
Tax regulations are found Sales orders cannot be rearranged when individual sales orders are tax regulated.
Remove the regulation on the orders, rearrange and regulate the tax on the summary order.
Update has been canceled because of an error.

Any help would be greatly appreciated.

Thanks,

Dave