Thursday, November 29, 2012

Example : Tally - XML Integration

Tally - XML Request / Response

Let us consider different scenarios to understand the Request and Response XML structure.
  • ExportRequest to Export Data and Corresponding response.
  • Import - Request to Import Data and the Corresponding response.
  • Execute - Request to Execute Action and Corresponding response.
Export

Tags used for sending a request to export data from Tally.ERP 9.
<HEADER> contains the following:
  • Tag <TALLYREQUEST> must contain value Export
  • Tag <TYPE> must contain value Data
  • Tag <ID> should contain the Name of the TDL Report
<BODY> contains the following:
  • Tag <DESC> can contain report settings like Company Name, Format, etc. as desired which should be enclosed within <STATICVARIABLES> tag.
  • If the Report Name specified in the <ID> tag does not exist within Tally running at the spec­ified port, the TDL defining the Report & other supporting definition needs to be described and enclosed within tag <TDL>.
Example :  Request for a detailed Trial Balance in XML Format from Tally.

<ENVELOPE>
     <HEADER>
             <VERSION>1</VERSION>
             <TALLYREQUEST>Export</TALLYREQUEST>
             <TYPE>Data</TYPE>
             <ID>Trial Balance</ID>
     </HEADER>
     <BODY>
             <DESC>
                     <STATICVARIABLES>
                               <EXPLODEFLAG>Yes</EXPLODEFLAG>
                               <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
                     </STATICVARIABLES>
             </DESC>
     </BODY>
</ENVELOPE>

In the above XML request, <HEADER> describes the expected result.
  • The value of the Tag <TALLYREQUEST> is Export which indicates that some information needs to be exported from Tally.
  • The value of the Tag <TYPE> is Data which indicates that the data needs to be exported from Tally.
  • The value of the Tag <ID> must be a TDL Report Name, if the previous Tag <TYPE> con­tains Data and Tag <TALLYREQUEST> contains Export. Any Report which needs to be exported from Tally can be specified within this Tag.
  • <BODY> Tag contains parameters, if any. Additional settings for the report like format required, company from which data is required, etc. can be passed within <STATICVARIA­BLES> Tag enclosed within <DESC> Tag. All variables are considered as Tag Names and their value are enclosed within these tags. For e.g., in the above XML, variables SVEX­PORTFORMAT and EXPLODEFLAG are considered as Tags and their respective values $$SysName:XML and Yes are enclosed within. TDL Internal Function SysName is evalu­ated at Tally end and the response is being sent accordingly.
XML Response received From Tally

<ENVELOPE>
         <DSPACCNAME>
                  <DSPDISPNAME>Capital Account</DSPDISPNAME>
         </DSPACCNAME>
         <DSPACCINFO>
                  <DSPCLDRAMT>
                           <DSPCLDRAMTA></DSPCLDRAMTA>
                  </DSPCLDRAMT>
                  <DSPCLCRAMT>
                           <DSPCLCRAMTA>100000.00</DSPCLCRAMTA>
                  </DSPCLCRAMT>
         </DSPACCINFO>
         <DSPACCINFO>
                  <DSPCLDRAMT>
                           <DSPCLDRAMTA>-100000.00</DSPCLDRAMTA>
                  </DSPCLDRAMT>
                  <DSPCLCRAMT>
                           <DSPCLCRAMTA></DSPCLCRAMTA>
                  </DSPCLCRAMT>
         </DSPACCINFO>
           .
           .
           .
          </DSPACCNAME>
</ENVELOPE>

Import

Tally can import data objects either in the form of a Master or Voucher.
<HEADER> contains the following
  • Tag <TALLYREQUEST> must contain value Import
  • Tag <TYPE> must contain value Data and
  • Tag <ID> should contain the Import TDL Report i.e., either All Masters or Vouchers.
<BODY> contains the following
  • Tag <DESC> can contain report settings like Company Name, behavior of Import in case of duplicates found; as desired which should be enclosed within <STATICVARIABLES> Tag.
  • Tag <DATA> must contain the XML Data Fragment within Tag <TALLYMESSAGE> that needs to be imported
Example : Request for importing Master data in Tally

<ENVELOPE>
          <HEADER>
                    <VERSION>1</VERSION>
                    <TALLYREQUEST>Import</TALLYREQUEST>
                    <TYPE>Data</TYPE>
                    <ID>All Masters</ID
          </HEADER>
          <BODY>
                    <DESC>
                             <STATICVARIABLES>
                                        <IMPORTDUPS>@@DUPCOMBINE</IMPORTDUPS>
                             </STATICVARIABLES>
                    </DESC>
                    <DATA>
                             <TALLYMESSAGE>
                                        <LEDGER NAME="ICICI" Action = "Create">
                                                  <NAME>ICICI</NAME>
                                                  <PARENT>Bank Accounts</PARENT>
                                                  <OPENINGBALANCE>-12500</OPENINGBALANCE>
                                        </LEDGER>
                                        <GROUP NAME=" Bangalore Debtors" Action = "Create">
                                                   <NAME>Bangalore Debtors</NAME>
                                                   <PARENT>Sundry Debtors</PARENT>
                                        </GROUP>
                                        <LEDGER NAME="RK Builders Pvt Ltd" Action = "Create">
                                                   <NAME>RK Builders Pvt Ltd</NAME>
                                                   <PARENT>Bangalore Debtors</PARENT>
                                                   <OPENINGBALANCE>-1000</OPENINGBALANCE>
                                        </LEDGER>
                             </TALLYMESSAGE>
                    </DATA>
          </BODY>
</ENVELOPE>

In the above XML Request, Create action is used. Any of the following system formulae can be used to choose the required behavior in case the system encounters a ledger with the same name. The behavior is for the treatment of the Opening Balance which is being imported.
  • DupModify specifies that the current Opening Balance should be modified with the new one that is being imported.
  • DupIgnoreCombine specifies that the ledger if exists need to be ignored.
  • DupCombine specifies the system to combine both the Opening Balances. Ideally, this option is used when Data pertaining to Group Companies are merged together into a single company. 
On processing the above request for importing ledgers, the requested ledgers are created in Tally. 

XML Response received From Tally.

<RESPONSE>
           <CREATED>2</CREATED>
           <ALTERED>0</ALTERED>
           <LASTVCHID>0</LASTVCHID>
           <LASTMID>0</LASTMID>
           <COMBINED>0</COMBINED>
           <IGNORED>0</IGNORED>
           <ERRORS>0</ERRORS>
</RESPONSE>

The above XML Response is a log of masters created, altered, combined, ignored or not imported due to some errors. It also contains information pertaining to the last Master ID imported. For Alteration and Deletion of Masters, the Object action needs to be Alter or Delete respectively.

For instance, in the above example,

<LEDGER NAME="ICICI" Action = "Alter">
          <NAME>HDFC</NAME>

Name of an existing ledger ICICI will get altered to HDFC.

In case of Deletion, following line suffices

<LEDGER NAME="ICICI" Action = "Delete">

Execute

Tags used for sending a request to Execute an action from Tally.ERP 9.
<HEADER> contains the following:
  • Tag <TALLYREQUEST> must contain value Execute
  • Tag <TYPE> must contain value TDLAction and
  • Tag <ID> should contain the Name of the TDL Action
Example : Request for Executing Synchronization in Tally

<ENVELOPE>
           <HEADER>
                    <VERSION>1</VERSION>
                    <TALLYREQUEST>Execute</TALLYREQUEST>
                    <TYPE>TDLAction</TYPE>
                    <ID>Sync</ID>
           </HEADER>
</ENVELOPE>

In the above XML request, <HEADER> describes the expected result.
  • The value of the Tag <TALLYREQUEST> is Execute which indicates that some action needs to be executed in Tally.
  • The value of the Tag <TYPE> is TDLAction which indicates that some TDLAction has to be executed in Tally.
  • The value of the Tag <ID> must be a TDL Action Name. Any action which needs to be exe­cuted in Tally can be specified within this Tag.
Response XML Fragment for the above would be:

<ENVELOPE>
          <HEADER>
                    <VERSION>1</VERSION>
                    <STATUS>1</STATUS>
          </HEADER>
</ENVELOPE>

Friday, November 23, 2012

Tally - XML Integration test.

Tally - XML Request / Response test using Tally.Developer 9.

Tally.Developer 9 

Tally.Developer 9 is a comprehensive development environment designed specifically for the language TDL (Tally Definition Language). TDL is the development language of Tally.ERP 9 and is used to build additional functionalities into the product. It enables the programmers to develop and deploy solutions rapidly with ease.
Tally.Developer 9 is an editor, a search engine and a compiler as well. It also provides the tools to compile a TCP, migrate an encrypted TDL file, translate a string and to send XML request to Tally to get the response in XML format.

The TDL code can be configured to run on one, more or all Tally serial number(s) while creating the TCP (Tally Compliant Product) file. This enables the developer to control license usage and minimize revenue leakage. 

Tally Connector.

Tally Connector allows to send the XML request to Tally/any application and displays the response received in the Response window. It allows to save the request XML and Load the XML request from a file. The response received can be saved in a file as well. 

Example : Request for a detailed Trial Balance in XML Format from Tally.

Step 1 : - Open Tally.ERP 9 -> Load Company -> Minimize Tally Application.
 

Step 2 : - Open Tally.Developer 9.
Step 3 :- Go to Tools -> Tally Connector.

 
Step 4 :- Open Tally Connector.


 
Step 5 :- Specify the URL of Tally.ERP9 or any other application which will process the request.
e.g., if the XML request is sent to Tally application listening on port 9000 on the local system, the URL “http://localhost:9000” is specified.

 
Step 6 :- The standard HTTP headers can be specified in the Header box.

 
Step 7 :- The request to be sent is specified in the POST text box. (Copy – Paste the request xml text).
Step 8 :- click on the GO! Button in URL ( Step 5 :- ).


Step 9 :- The response received is displayed in the Response box. The response received can be saved in a file using the Save Request button.