Tally XML API issue

Here in the below schema i want to get the data of vouchers , stockitems, customer, but we can only type of data , but i need all them in one single response.

I want to get the data based on the alterid related to vouchers.

This is the schema i used

<ENVELOPE>
    <HEADER>
        <VERSION>1</VERSION>
        <TALLYREQUEST>EXPORT</TALLYREQUEST>
        <TYPE>COLLECTION</TYPE>
        <ID>CUSTOMCOLLECTION</ID>
    </HEADER>
    <BODY>
        <DESC>
            <STATICVARIABLES>
                <SVEXPORTFORMAT>$SysName:XML</SVEXPORTFORMAT>
            </STATICVARIABLES>

            <TDL>
                <TDLMESSAGE>
                    <COLLECTION ISMODIFY="No" ISFIXED="No" ISINITIALIZE="No" ISOPTION="No" ISINTERNAL="No" NAME="CUSTOMVOUCHERDATA">
                        <TYPE>VOUCHER</TYPE>
                        <FETCH>VOUCHERNUMBER,DATE,ISCANCELLED,PARTYNAME,PARTYLEDGERNAME,PARTYGSTIN,CONSIGNEEGSTIN,ALLLEDGERENTRIES.LIST.LEDGERNAME,AMOUNT,VCHSTATUSDATE,EFFECTIVEDATE,ALTERID,MASTERID,VOUCHERKEY,VOUCHERRETAINKEY,GUID,BASICSHIPDOCUMENTNO,BASICFINALDESTINATION,BASICSHIPVESSELNO,EICHECKPOST,BILLOFLADINGNO,BILLOFLADINGDATE,BILLOFLADINGDATE,BASICSHIPPEDBY,IRN,IRNACKDATE,GSTREGISTRATION,VOUCHERTYPENAME,CMPGSTREGISTRATIONTYPE,CMPGSTSTATE,NUMBERINGSTYLE,VCHSTATUSTAXUNIT,GSTNATUREOFRETURN</FETCH>
                        <FILTER>Masterfilter</FILTER>
                    </COLLECTION>
                    <SYSTEM TYPE="Formulae" NAME="Masterfilter">$MASTERID > 829 AND $ALTERID > 1343 </SYSTEM>                    
                </TDLMESSAGE>
            </TDL>

            <TDL>
                <TDLMESSAGE>
                    <COLLECTION ISMODIFY="No" ISFIXED="No" ISINITIALIZE="No" ISOPTION="No" ISINTERNAL="No" NAME="CUSTOMSTOCKITEMCOL">
                        <TYPE>STOCKITEM</TYPE>
                        <FETCH>NAME,GUID,GSTAPPLICABLE,GSTDETAILS.LIST,ALTERID,MRPDETAILS.LIST,BASEUNITS,ISDELETED,OPENINGBALANCE,OPENINGRATE</FETCH>
                        <FILTER>Masterfilter</FILTER>
                    </COLLECTION>
                    <SYSTEM TYPE="Formulae" NAME="Masterfilter">$ALTERID > 1094</SYSTEM>
                </TDLMESSAGE>
            </TDL>
            
            <TDL>
                <TDLMESSAGE>
                    <COLLECTION ISMODIFY="No" ISFIXED="No" ISINITIALIZE="No" ISOPTION="No" ISINTERNAL="No" NAME="CUSTOMLEDGERDATA">
                        <TYPE>LEDGER</TYPE>
                        <FETCH>NAME,PARENT,GUID,PARTYGSTIN,BILLCREDITPERIOD,LEDGERMOBILE,LEDGERCOUNTRYISCODE,ISDELETED,ALTERID,EMAIL,PRIORSTATENAME</FETCH>
                        <FILTER>Masterfilter</FILTER>
                    </COLLECTION>
                    <SYSTEM TYPE="Formulae" NAME="Masterfilter">$ALTERID > 32</SYSTEM>
                </TDLMESSAGE>
            </TDL>

        </DESC>
    </BODY>
</ENVELOPE>

To retrieve all the required data (vouchers, stock items, and customer/ledger) in a single response, you need to use multiple collections within the same TDL request. However, the challenge is that Tally generally processes and returns one collection at a time. If you want all data in a single response, you can combine the collections logically in your TDL request.

Below is an updated TDL schema to achieve this:

Updated TDL Schema

<ENVELOPE>
    <HEADER>
        <VERSION>1</VERSION>
        <TALLYREQUEST>EXPORT</TALLYREQUEST>
        <TYPE>COLLECTION</TYPE>
        <ID>CUSTOMCOLLECTION</ID>
    </HEADER>
    <BODY>
        <DESC>
            <STATICVARIABLES>
                <SVEXPORTFORMAT>$SysName:XML</SVEXPORTFORMAT>
            </STATICVARIABLES>

            <!-- Combined Data Collection -->
            <TDL>
                <TDLMESSAGE>
                    <COLLECTION ISMODIFY="No" ISFIXED="No" ISINITIALIZE="No" ISOPTION="No" ISINTERNAL="No" NAME="COMBINEDDATA">
                        <TYPE>VOUCHER, STOCKITEM, LEDGER</TYPE>
                        <FETCH> 
                            <!-- Voucher Fields -->
                            VOUCHERNUMBER, DATE, ISCANCELLED, PARTYNAME, PARTYLEDGERNAME, 
                            ALLLEDGERENTRIES.LIST.LEDGERNAME, AMOUNT, ALTERID, MASTERID,
                            VOUCHERTYPENAME, IRN, GSTNATUREOFRETURN,

                            <!-- Stock Item Fields -->
                            NAME:STOCKITEM, GUID:STOCKITEM, GSTAPPLICABLE:STOCKITEM,
                            BASEUNITS:STOCKITEM, OPENINGBALANCE:STOCKITEM, ALTERID:STOCKITEM,

                            <!-- Ledger Fields -->
                            NAME:LEDGER, PARENT:LEDGER, PARTYGSTIN:LEDGER,
                            LEDGERMOBILE:LEDGER, ALTERID:LEDGER
                        </FETCH>
                        <FILTER>CombinedFilter</FILTER>
                    </COLLECTION>

                    <!-- Filter Definition -->
                    <SYSTEM TYPE="Formulae" NAME="CombinedFilter">
                        $ALTERID:VOUCHER > 1343 OR $ALTERID:STOCKITEM > 1094 OR $ALTERID:LEDGER > 32
                    </SYSTEM>
                </TDLMESSAGE>
            </TDL>

        </DESC>
    </BODY>
</ENVELOPE>

Explanation of the Updates

  1. TYPE includes multiple entities:
  • The TYPE field of the COLLECTION is set to include VOUCHER, STOCKITEM, and LEDGER.
  • This allows the collection to fetch data from multiple entity types in Tally.
  1. Combined Fetch Fields:
  • Fields from VOUCHER, STOCKITEM, and LEDGER are included under the FETCH section.
  • Prefixes like NAME:STOCKITEM and ALTERID:LEDGER are used to specify the context for ambiguous field names.
  1. Filter for Combined Data:
  • A CombinedFilter formula ensures that relevant records are fetched based on the ALTERID of each entity type.
  1. Single Collection Response:
  • The COMBINEDDATA collection consolidates the data into one unified response.

Notes:

  • Dependencies: Tally needs to support fetching multiple entity types in a single request. If it does not, you may need to make separate requests and merge the data in your application layer.
  • Output Format: The response will include all fetched data in a combined XML format. You can parse and segregate this data in your integration logic.

Let me know if further adjustments are required!