Search code examples
node.jsxmlcurlencodingtally

Error in exporting other language text as ???? in Tally data


While exporting Tally data from Tally, it supports multilanguage texts, but while executing an XML file from another source like, a cmd or Postman request, the other language texts are returned like ? symbols.

My code is:

<?xml version="1.0" encoding="UTF-8"?>
  <ENVELOPE>
  <HEADER>
   <TALLYREQUEST>ExportData</TALLYREQUEST>
   </HEADER>
   <BODY>
   <EXPORTDATA>
   <REQUESTDESC>
   <REPORTNAME>TNetSA LedgerSalesorders</REPORTNAME>
   <STATICVARIABLES>
   <SVCURRENTCOMPANY>${companyName}</SVCURRENTCOMPANY>
   <SVFROMDATE>${fromDate}</SVFROMDATE>
   <SVTODATE>${toDate}</SVTODATE>
   <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
   </STATICVARIABLES>
   </REQUESTDESC>
   </EXPORTDATA>
   </BODY>
   </ENVELOPE>

Post request UTF-8

Header=> Content-Type:application/xml; charset=utf-8

https://i.sstatic.net/T9WDW.png

UTF-16

Header=> Content-Type:application/xml; charset=utf-16

https://i.sstatic.net/S4J7H.png

Using Curl commands

  curlcommand = cd  C:\Users\..\Data\ && curl -H "Content-Type: text/plain; charset=UTF-8" localhost:9001 --data @Basic\I_SPND.xml

https://i.sstatic.net/PJpAK.png

Node.js:

const asynchronousProcess = () => {
    var inputFilename = Path + 'I_SPND.xml'; // Path of the stored above XML code
    fs.writeFile(inputFilename, values, 'utf8', function (err) {
        if (err) {
            return console.log(err);
        }
    });
    return new Promise((resolve, reject) => {
        let cmd = curlcommand; // The above mentioned curl command
        exec(cmd, (error, stdout, stderr) => {
            if (error) {
                reject(error);
            }
            resolve(stdout ? stdout : stderr);
        });

    });
}

For example: If PartyLedgerName is in another language text result will be?

While running on the Tally developer tool, it is supporting multilanguage texts, but on posting a request or using a curl command means it is not supporting it.


Solution

  • You need to install "node-fetch": "^3.2.10"

    Sample Node.js Snippet

    import fetch from 'node-fetch';
    
    let SourceXml = "<ENVELOPE Action=\"\"><HEADER><VERSION>1</VERSION><TALLYREQUEST>EXPORT</TALLYREQUEST><TYPE>COLLECTION</TYPE><ID>CUSTOMLEDGERCOL</ID></HEADER><BODY><DESC><STATICVARIABLES /><TDL><TDLMESSAGE><COLLECTION ISMODIFY=\"No\" ISFIXED=\"No\" ISINITIALIZE=\"No\" ISOPTION=\"No\" ISINTERNAL=\"No\" NAME=\"CUSTOMLEDGERCOL\"><TYPE>LEDGER</TYPE><FETCH>   NAME </FETCH><FILTERS>LedgFilter</FILTERS></COLLECTION><SYSTEM TYPE=\"Formulae\" NAME=\"LedgFilter\">$Name = \"Test Party_altered\"</SYSTEM></TDLMESSAGE></TDL></DESC></BODY></ENVELOPE>"
    let buffer = Buffer.from(SourceXml, 'utf16le')
    
    function test() {
        fetch('http://localhost:9000', {
            method: 'POST', body: buffer, headers: {
                'Content-Type': 'application/xml; charset=utf-16',
            },
        })
            .then(res => res.blob())
            .then(async data => {
                const buffer = Buffer.from(await data.arrayBuffer());
                console.log(buffer.toString('utf16le'));
            })
    }
    test()
    

    Output:

    Enter image description here