Sunday, 25 December 2016

Transaction Log - AX 2012 - Cannot create a record in Audit trail (TransactionLog)

 If you got the following error you might have for problems in the system sequence table.

 Just run the following in SSMS:

select * from SYSTEMSEQUENCES where id = -2

 and then


 If you have any records returned by the second statement then you should look into why you have a lower system number saved.

To over come this issue, please find the below code modifications in Tables-->TransactionLog-->Methods-->create.
The existing Code:

if (appl.lastTransactionIdCreated() != appl.curTransactionId())
transactionLog.Type = _type;
transactionLog.Txt = _txt;




The changes to make: 

if (appl.lastTransactionIdCreated() != appl.curTransactionId())
if (!TransactionLog::find(appl.curTransactionId()))
transactionLog.Type = _type;
transactionLog.Txt = _txt;



Wednesday, 27 July 2016

Axapta 2012 set financial dimension x++

 InventTable _InventTable; 
    RecId _RecId;   
    DimensionAttributeValueSetStorage  dimStorage;
    Counter               i;
    DimensionAttribute         _dimAttribute;
    DimensionAttributeValue       _dimAttributeValue;
  while  select forUpdate _InventTable where _InventTable.ProdPoolId == '0101'
    _RecId = _InventTable.RecId;
      dimStorage = DimensionAttributeValueSetStorage::find(_RecId);
     _dimAttribute = DimensionAttribute::findByName("AF_Department",false);
     _dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimAttribute,"501",true,true);
     _dimAttribute = DimensionAttribute::findByName("AF_Product_Section",false);
     _dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimAttribute,"01",true,true);
     _dimAttribute = DimensionAttribute::findByName("AF_Product_Line",false);
     _dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimAttribute,"0111",true,true);
    _InventTable.DefaultDimension =;
    info('Done ' + _InventTable.ItemId );

Sunday, 24 July 2016

AX 2012 The simplest way to lookup the financial dimension in a form

In this article, giving an example for defining the lookup for dimensions in simple way.
This example will cover only for user Defined dimensions.
For this
1)      Created a form and added two string controls.
2)      Named as
Control: Name: Dimensionlist, Auto declaration – Yes
Control: Name: DimValues
3)      Override the lookup method for Dimensionlist

public void lookup()
Query           query;
SysTableLookup  sysTableLookup;
sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionAttribute), this);
sysTableLookup.addLookupfield(fieldNum(DimensionAttribute, Name));
query = new Query();
addRange(fieldNum(DimensionAttribute, Type)).


4)      Override the lookup method for DimValues
public void lookup()
DimensionAttribute                  dimensionAttribute;
DimensionAttributeDirCategory       dimAttributeDirCategory;
Query                               query = new Query();
SysTableLookup                      sysTableLookup;
dimensionAttribute = DimensionAttribute::findByName(Dimensionlist.text());
// Only user defined dimensions will have a financial tag category
if (dimensionAttribute.Type == DimensionAttributeType::CustomList)
select firstonly DirCategory from dimAttributeDirCategory where dimAttributeDirCategory.DimensionAttribute == dimensionAttribute.RecId;
sysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag), this);
// Add name field to be shown in the lookup form.
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Value));
sysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag, Description));
query = new Query();
addRange(fieldNum(DimensionFinancialTag, FinancialTagCategory)).
// Perform the lookup.

Monday, 18 July 2016

Read XML string (elements, attributes, texts) [AX2012]

static void readXMLString(Args _args)
    // Define XML Document and its nodes
    XmlDocument     doc;
    XmlNodeList     xmlScriptList;
    XmlNodeList     xmlProjectList;
    XmlElement      nodeScript;
    XmlElement      nodeProject;
    XmlElement      nodeNote;
    XMLParseError   xmlError;
    // Define temporary variables
    str _xmlMsg;
    int i, j;


    // XML string to read
    _xmlMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><XMLScript Version=\"2.0\"><Project Name=\"Holidays\"><Format>C:\NotesDesign\Note.jpg</Format><PrintSetup><Printer>PDFPrinter</Printer></PrintSetup><Note Date=\"2014/12/10\" ID=\"N001\"><To>Tim</To><Body>Make sure all tasks are completed before holidays!</Body></Note><Note Date=\"01/01/2015\" ID=\"N002\"><To>Sophie</To><Body>Don't forget your Christmas shopping this weekend!</Body></Note></Project></XMLScript>";

    // Create the XML Document
    doc = new XmlDocument();

    // Verify XML Document Structure
    xmlError  = doc.parseError();
    if(xmlError && xmlError.errorCode() != 0)
        throw error(strFmt("XML Error: %1", xmlError.reason()));

    // Get the root element and its child nodes
    nodeScript = doc.getNamedElement("XMLScript");
    xmlScriptList = nodeScript.childNodes();

    for(i=0; i < xmlScriptList.length(); i++)
        nodeProject = xmlScriptList.item(i);
        xmlProjectList = nodeProject.childNodes();

        info("### Project information: ");

        // Print out node and attribute values
        info(strFmt("XML Document Version: %1", nodeScript.getAttribute("Version")));
        info(strFmt("Project Name: %1", nodeProject.getAttribute("Name")));
        info(strFmt("Format: %1", nodeProject.getNamedElement("Format").text()));
        info(strFmt("PrintSetup (innerXML): %1", nodeProject.getNamedElement("PrintSetup").innerXml()));
        info(strFmt("Printer (text): %1 OR Printer (innerText): %2", 

        // Loop through the repeating nodes
        info("### Notes: ");       
        for (j=2; j < xmlProjectList.length(); j++)
            nodeNote = xmlProjectList.item(j);

            info(strFmt("ID: %1, Date: %2", nodeNote.getAttribute("ID"), nodeNote.getAttribute("Date")));
            info(strFmt("To: %1", nodeNote.getNamedElement("To").text()));
            info(strFmt("Body: %1", nodeNote.getNamedElement("Body").text()));

X++: HTTP Web Request to URL

//This method makes HTTP web request to the given url and returns the response
System.Net.WebRequest webrequest;

System.Net.HttpWebResponse httpresponse;

System.IO.Stream stream;

System.IO.StreamReader streamReader;

xml responseXML;

System.Byte[] arrayOfBytes;

System.Text.Encoding encoding;
System.String netString = "Net string.";
  System.Exception netExcepn;




new InteropPermission(InteropKind::ClrInterop).assert();

//Use .Net framework reflections to make HttpRequest and get the response back

encoding = System.Text.Encoding::get_UTF8();
arrayOfBytes = encoding.GetBytes("");

webrequest = System.Net.WebRequest::Create('http://localhost/AxService/myService.asmx/HelloWorld');


stream = webrequest.GetRequestStream();
stream.Close ();

httpresponse = webrequest.GetResponse();

stream = httpresponse.GetResponseStream ();

streamReader = new System.IO.StreamReader (stream);

responseXML = streamReader.ReadToEnd ();

streamReader.Close ();

stream.Close ();

httpResponse.Close ();


 catch (Exception::Error)
        info("Caught 'Exception::Error'.");
    catch (Exception::CLRError)
        info("Caught 'Exception::CLRError'.");
        netExcepn = CLRInterop::getLastException();

Thursday, 16 June 2016

Axapta 2009 This transaction has been marked for settlement by another user.

one of end user of AR is got stuck for knock off the account.
Then I  make  a solution that logon to database server of the AX 2009 then write a query
select * from SPECTRANS
then select a amount in table where Red Dot is came and put in the query
select * from SPECTRANS where BALANCE01=398.700
now check that record is came
Now delete that record by writing a query
delete from SPECTRANS where  BALANCE01=398.700
now again go to check the settlement transaction ,Red Dot  is gone .

Monday, 25 April 2016

Overdelivery of line is 100,00 percent, but the allowed overdelivery is only 0 percent.

We had the same problem with one of our client. The reason behind was, there were some orphans purchParmSubLine records lying in the table, which led to add up the remain del note qty and attempting to post Delivery note again. We suspected, the reasons these records were left in the table, when posting failed for any reason or client session crashed when posting was being done. Anyways, simple way to resolve it by creating a simple job to clean up those records and Hallelujah! the problem is gone!
static void tecDeleteOrphanParmRecords(Args _args)
   PurchParmTable purchParmTable;
   PurchParmLine  purchParmLine;
   while select forupdate purchParmTable
       join forupdate purchParmLine
       where purchParmLine.ParmId == purchParmTable.ParmId
       && purchParmLine.TableRefId    == purchParmTable.TableRefId
       && purchParmTable.PurchId  == "Your PO number"
       && purchParmTable.ParmJobStatus == ParmJobStatus::Waiting
       && purchParmTable.Ordering == DocumentStatus::Invoice
   if(purchParmTable.RecId || purchParmLine.RecId)
Cleaning up PurchParmTable and Line will also clean up related tables (Sub tables) by itself.
Try posting again.  Everything should work smoothly.

Monday, 15 February 2016

Send email using X++ code

SysMailer   mailer = new SysMailer();
        SysEmailParameters parameters = SysEmailParameters::find();

        if (parameters.SMTPRelayServerName)

        mailer.subject('Comunicazione AX');


Tuesday, 26 January 2016

Can not post a purchase invoice

We have come across some scenarios where it was not possible to complete purchase invoicing, for example:
  • There is pending invoice in AX that is not visible in invoicepool. It can be seen only from purchase order side. It blocks many orders.
  • A Pending Invoice is not appearing in PL>common>Pending Supplier Invoices however when you go to the PO and look at the invoice tab, the Pending Invoice is still highlighted and when you select this you can see the detail of the pending invoice but we cannot do anything with it
  • When trying to post a purchase invoice you get an error message that says: Invoice %1 could not post because it contained matching errors which must be approved.
  • While selecting Pending vendor invoice gets an error as “One or more pending invoices cannot be displayed because they are in use” and the invoice is not displayed.
It may happen that if AOS gets stopped suddenly or the client loses connection with the AOS, some records stay in specific tables that causes these kind of situations. In other cases we or Partners could not find repro steps to get those scenarios.
I found a list of the SQL tables where the ‘pending’ record may exist. If the record is found in any of the following tables, the recommendation is to remove it when you have no users accessing AOS (and take normal precautions first of backing up the data). Also test the procedures in a test/development environment before applying it to a live enviroment. Then, check to see if you are able to properly invoice update the PO.
Of course, you can also delete these records going through Forms, these are the ones I used (ensure no users besides you are working in the application):
1. Firstly checking PurchParm tables when looking History forms (Account Payable/ Inquiries/ History/ Purchase orders), and delete those records where the status is “Waiting”.
2. The next step is to check VendInvoiceInfo tables where you found the wrong records, You can access those records in the list page: Accounts payable module > Places > Pending Purchase Order Invoices. Here you can delete it as well. Note: pending invoice of your case will be in this list page.
Hope it’s helpful


Friday, 15 January 2016

Unreserved "Physical Reserved" Qty in Ax 2009 thru x++

To remove a reservation (just reverse the sign on the qty):
In the code below, ‘inventTransParent’ is the inventTransId of the record that has the reservation (e.g. salesline.inventTransId)
You probably will want to modify the ‘where’ clause a bit to make sure you get the reservation records only, but this is just an example.
//Remove any existing reservations
InventTrans            inventTransReserve    ;
InventMovement         inventMovement        ;
InventUpd_Reservation  inventUpd_Reservation ;
while select inventTransReserve where inventTransReserve.InventTransId == inventTransParent
   Inventmovement = inventTransReserve.inventmovement(true);
   inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTransReserve.inventDim(), -1 * inventTransReserve.Qty ,false);    inventUpd_Reservation.updatenow();