Monday, March 24, 2014

IND Localization: Creating Sales Order through code in AX 2012, system error "TIN number must be filled in"

When this error occurs ?

When auto generating Sales Orders in IND Localization through code in AX2012, system will not allow confirmation or proceeding further with the SO and will through error "TIN number must be filled in"

Why this error ?

This error occurs due to unhandled cases not considered for India localization. SalesLine_IN is the IND localization table for Sales Order in AX 2012 where the India tax related mandatory information is stored. Default Sales Order creation code for e.g. SalesLine.createline(1,1,1,1,1) fails to insert required mandatory data in SalesLine_IN.

Solution

Override the insert() table-method in SalesLine_IN as follows:
 
public void insert()
{
    if (this.SalesLine != 0)
    {
        // only insert if the Foreign key is valid
        this.initValue(); 
        super();
    }
}
 
Now use any standard code for sales line creation, which will succeed without any error during execution. One sample code, that I use is as follows ->
 
############################################
    AxSalesLine axSalesLine = new axSalesLine();   
    SalesLine               salesL;
    salesTable              salesT = salesTable::find(_salesId);
    real                    price = 99.99;
    itemid                item = "1001";
    qty                      qty = 4;
    ;
    salesL.initFromSalesTable(salesT);
    salesL.initValue(SalesType::Sales);
    salesL.ItemId = item;
    salesL.initFromInventTable(InventTable::find(_lensid));
    salesL.SalesQty = qty;
    salesL.PriceUnit = price ;
    salesL.SalesPrice = qty * price;
    salesL.createLine(1,1,0,1,1);
#############################################

Create your own custom web service in AX 2012 and host it in AOS

Creating custom service in AX 2012

 
Step 1:

Create two classes in AX. One class should instantiate other class as follows:
1st class should like this ->
 




 
 


2nd class should look like this ->




 
Step 2:

 

Right click “Services”node and click New Service.
Add the service as below:



 
Assign a service name and assign Calling class in Step 1 as Class field value in properties window.

Right click Operation node and click “Add Operation”, this will automatically show the methods under that class. Click on the “Add” tick box field in each method to publish them into service.

 

Step 3

Right click “ServiceGroups” node and click New  -> Service Group.

Add the service as below:

 

Drag and drop the Service created in Step 2 under this group node. Right Click on the service group node and select “Deploy Service Group”. This should show a success infolog like this :

 

Step 4

Open Inbound Port list form and check if the newly deployed service is added there with state Active.
Copy the WSDL URI, which is this in my case:
 

Step 5

In VS 2010, create a new project of type Console Application. Add the Service Reference (WSDL URI) and write the code like below to consume the web service hosted by AX.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SUV_AX2012_ConsoleAppl_CustNameDemo.SUV_CustNameDemoGroup; 

namespace SUV_AX2012_ConsoleAppl_CustNameDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            SUV_CustNameDemoClient Client = new SUV_CustNameDemoClient();
            string CustName = Client.getCustName(null);
            Console.WriteLine(CustName);
            Console.ReadLine(); 

        }
    }
}

 
Step 6
Run the Code by clicking F5 or clicking the Run button. I got an out like this.
 

 




 

Sunday, March 23, 2014

Voucher is already used as of date 2/24/2014 - common number sequence conflict error in AX 2012 R2 while posting PO invoice


Why this error ?
This error or similar error happens because, all system defined number sequences are prefixed with “<Data Area Id> –#####“ and many of them has got same number format as well. Incidentally some of them are saved in same table as primary key value such as GeneralJournalEntry.  This error pops up when one running sequence catches other sequence. 

This coincidence is hardly possible in test phase and likely to occur in production  scenario after a few days or weeks depending upon the transaction volume. 

In this case, (DEMO is a test company account which is smudged in the attached error screen) the voucher number sequence set up under IM -> Inventory credit note costing (Inve_89 by auto number sequence assign wizard) voucher intercepts with IM -> Inventory costing voucher (Inve_91) number sequence.

Solution

Very simple. Change the number sequence format of Inve_91 or Inve_89 so that it has no possibility of interference in future.