Collection Attributes
Data Source
When you integrate TallyPrime with a third-party application, the communication can happen in a connected or non-connected environment where TallyPrime can act as a client or server or both.
The collection attribute Data Source is used to populate data to a collection dynamically from a variety of data sources. This attribute accepts the Type and Identity of the data source from where the data is to be retrieved.
Syntax
[Collection: <Collection Name>]
Data Source : <Type>: <Identity>: [<Encoding>]
<Type> specifies the type of data source.
<Identity> is the data source file path or URL.
<Encoding> values can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. This is an optional parameter. The default value is UNICODE.
In this section
- HTTP JSONEx
- HTTP JSON
- HTTP XML
- File JSON
- File XML
- Plugin JSON
- Plugin XML
- Ax Plugin XML
- JSON String
- XML String
| <Type> of DataSource | Purpose |
| HTTP JSONEx | For JSON Data Exchange over HTTP. Here Request is sent in well structure JSON with valid keys and syntax. JSON response is gathered in the collection |
| HTTP JSON | For JSON Data Exchange over HTTP. Here Request is flat JSON structure. JSON response is gathered in the Collection. |
| HTTP XML | For XML data Exchange over HTTP. |
| File JSON | To Read JSON data from a JSON File. |
| File XML | To Read JSON data from an XML File. |
| Plugin JSON | To Integrate with DLL with output in JSON format. |
| Plugin XML | To Integrate with C++ based DLL with output in XML format. |
| Ax Plugin XML | To Integrate with DLLs created in VB, VB.Net, etc. with output in XML format. |
| JSON String | To read JSON data from a JSON data provided as a direct string. |
| XML String | To read XML data from an XML data provided as a direct string. |
HTTP JSONEx
From Release 7.0, the Collection attribute Data Source accepts a new data source type as HTTP JSONEx, which sends HTTP requests in a new structured JSON format to the specified URL and gathers response received in JSON format in the Collection.
This attribute is like HTTP JSON, but the only difference being the JSON format in which the requests are sent using the Remote Request attribute, which is in a well-structured format with valid keys and syntax.
Syntax
[Collection: <Collection Name>]
Data Source: HTTP JSONEx : <Target URL> [:<Encoding>]
Where,
<Collection Name> is the name of the collection where the data is populated.
<Target URL> is the URL to which the request is to be sent.
<Encoding> can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
When you use HTTP JSONEx as data source type
- The behaviour of the data source type HTTP JSONEx is like HTTP JSON. Only difference is that when post request sent using Remote Request, the format of JSON follows the new structured JSON format introduced in TallyPrime Release 7.0.
- The attributes JSON Object Path and JSON Object , are applicable here.
- Use the attribute Remote Request to send a POST request. For a GET request, only the HTTP data source is used.
- Encoding for POST requests: If the attribute Remote Request is specified, the specified encoding will override the Data Source attribute encoding. Hence both the request and response encodings will be the same.
- Encoding for GET requests: The encoding for a response is taken from the attribute Data Source encoding. If encoding is not specified for the attribute Data Source, the default encoding is UNICODE or UTF16.
Example
Case 1: Sending Post request with HTTP JSONEx
[Collection: TSPLBalanceSheetJsonPost]
Data Source: HTTP JSON Ex: “http://localhost/HttpJson/BalanceSheetPost.php“
Remote Request: Balance Sheet: UTF8
{
“bsbody”: {
“bsinfo”: {
“bssources”: {
“bsdetail”: [
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Capital Account”
}
},
“bsamt”: [
{
“bsmainamt”: 7400000.00
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Loans (Liability)”
}
},
“bsamt”: [
{
“bsmainamt”: 3555806.00
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Current Liabilities”
}
},
“bsamt”: [
{
“bsmainamt”: 1822674.91
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Branch / Divisions”
}
},
“bsamt”: [
{
“bsmainamt”: -1207798.00
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Suspense A/c”
}
},
“bsamt”: [
{
“bsmainamt”: 9890.22
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Profit & Loss A/c”
}
},
“bsamt”: [
{
“bsmainamt”: 4290002.47
}
]
}
]
},
“bsapp”: {
“bsdetail”: [
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Fixed Assets”
}
},
“bsamt”: [
{
“bsmainamt”: -6263198.00
}
]
},
{
“bsname”: {
“dspaccname”: {
“dspdispname”: “Current Assets”
}
},
“bsamt”: [
{
“bsmainamt”: -9600186.34
}
]
}
]
}
}
}
}
{
“Status”: 1,
“Message”: “Data Received Successfully”
}
Case 2: GET Request with HTTPJSONEx
The following code snippet sends a GET request to the URL mentioned and receives list of branches as a response in JSON format.
[Collection: TSPLGetBranchesColl]
Data Source : HTTP JSONEx: “http://localhost/HttpJson/getbranchlist.php“
JSON Object Path: “BranchName:1“
The response in JSON format.
{
“BranchName“:
[
“East“,
“North East“,
“North“,
“West“,
“South“
]
}
NOTE: GET Request with HTTP JSON and HTTP JSONEx works the same way as there is no payload sent in the request.
HTTP JSON
From Release 6.4.1, the collection attribute Data Source accepts a new data source type as HTTP JSON. Use this attribute to specify a URL as source of data and send request and gather data from the response received in JSON format, from the URL over HTTP, in ASCII, UTF8 or UTF16 encodings.
Syntax
[Collection: <Collection Name>]
Data Source: HTTP JSON : <Target URL> [:<Encoding>]
Where,
<Collection Name>is the name of the collection where the data is populated.
<Target URL> is the URL to which the request is to be sent.
<Encoding> can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
When you use HTTP JSON as data source type
- The behaviour of data source type HTTP JSON is similar to HTTP XML. Only difference is the format of exchange. Hence the behaviour of the sub-attributes as well as the behaviour of the attribute Remote Request remains same, if specified.
- The data source type HTTP JSON is an enhancement over the File JSON data source, where the source JSON is obtained over HTTP/HTTPS. The attributes related to File JSON, namely JSON Object Path and JSON Object, are applicable here.
- Use the attribute Remote Request to send a POST request. For a GET request, only the HTTP data source is used.
- Encoding for POST requests: If the attribute Remote Request is specified, the specified encoding will override the Data Source attribute encoding. Hence both the request and response encodings will be the same.
- Encoding for GET requests: The encoding for a response is taken from the attribute Data Source encoding. If encoding is not specified for the attribute Data Source, the default encoding is UNICODE or UTF16.
Example
Case 1: Reading data from a GET Request
The following code snippet sends a GET request to the URL mentioned and receives list of branches as a response in JSON format.
[Collection: TSPLGetBranchesColl]
Data Source : HTTP JSON: “http://localhost/HttpJson/getbranchlist.php“
JSON Object Path: “BranchName:1“
The response in JSON format.
{
“BranchName“:
[
“East“,
“North East“,
“North“,
“West“,
“South“
]
}
Case 2: Sending POST Request to a server and reading the response
The following code snippet sends a POST request to the URL mentioned with the branch name, and receives customer details of the branch, in JSON format.
[Collection: TSPLBranchCustomers]
Data Source: HTTP JSON: “http://localhost/HttpJson/branchcustomers.php“
Remote Request: TSPL Branch Customers: ASCII
[Report: TSPLBranchCustomers]
Form : TSPLBranchCustomers
……
……
[Field: TSPLBranchName]
Set As: “North“
JSON Tag : “Branch“
| Request Sent | Response Received |
|
{ “Branch“: “North“ } |
{ “Branch“: “North“, “Customer“: [ { “Name“: “Sapna Awasthi“, “State“: “Delhi“ }, { “Name“: “Ashish Rai“, “State“: “Delhi“ } ] } |
HTTP XML
When data exchange happens over HTTP in XML format, data source HTTP XML is used. The Target URL for either a GET or POST request is specified here, and the XML data received in the response is collected.
Syntax
[Collection: <Collection Name>]
Data Source: HTTP XML : <Target URL> [:<Encoding>]
Where,
<Collection Name> is the name of the collection where the data is populated.
<Target URL>is the URL to which the request is to be sent.
<Encoding> can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
Example
[Collection: TSPL Get Employees XML]
Export Header : “Accept:application/xml”
Export Header : “Accept-Charset:utf-8”
Data Source : HTTP XML:”http://localhost/ExportHeader/getempdetails.php”:UTF8
XML Object Path: “employee:1:employees”
This example demonstrates an XML GET request with HTTP headers to retrieve employee details from the URL. The starting point for parsing the response data is specified by the XML Object Path attribute.
Response
<employees>
<employee>
<Name>Rashmi Reddy</Name>
<Department>Marketing</Department>
<Gender>Female</Gender>
<EmpId>5989</EmpId>
</employee>
<employee>
<Name>John Fernandes</Name>
<Department>RnD</Department>
<Gender>Male</Gender>
<EmpId>5145</EmpId>
</employee>
</employees>
File JSON
In Release 6.2, the collection attribute Data Source allows to specify the data source type as File JSON where you can create the collection directly from the specified JSON file.
Syntax
[Collection: <Collection Name>]
Data Source: File JSON : <File path>
Where,
<Collection Name> is the name of the collection where the data is populated
<File Path> is the JSON file name including its path.
Example
[Collection: TSPL Stock Item Price List]
Data Source : File JSON: “stockitempricelist.json”
JSON Object Path : “Stockitems:1”
{
“Stockitems”: [
{
“StockItem”: “Crackers – rocket”,
“Unit”: “nos”,
“Pricelist”: [
{
“Price Level Name”: “Diwali offer 1”,
“Price Date”: “1-Apr-2017”,
“Pricelevellist”: [
{
“Disc”: “25”,
“Ending”: “150”,
“Rates”: “20”,
“Starting”: “0”
},
{
“Disc”: “30”,
“Ending”: “300”,
“Rates”: “15”,
“Starting”: “150”
}
]
}
]
}
]
}
File XML
The collection attribute Data Source allows to specify the data source type as File XML where you can create the collection directly from the specified XML file.
Syntax
[Collection: <Collection Name>]
Data Source: File XML : <File path>
Where,
<Collection Name> is the name of the collection where the data is populated
<File Path> is the XML file name including its path.
Example
[Collection: XML Data Source Explode Exp]
Data Source : File XML : “\MyFile.XML”
XMLObjectPath : Object : 1 : Collection
Data in XML File
<Collection>
<Object>
<Name>Ledgers</Name>
<FileName>XMLData\MyLedgers.xml</FileName>
</Object>
<Object>
<Name>Stock Items</Name>
<FileName>XMLData\MyStockItem.xml</FileName>
</Object>
</Collection>
Plugin JSON
By using this attribute, we can invoke the DLL and convert the returned values into TDL objects for further processing. The value returned by the DLL is in JSON format. The type specification in the Data source attribute, in this case is Plugin JSON.
Syntax
[Collection: <Collection Name>]
Data Source : Plugin JSON : <Identity>[:<Encoding>]
Where,
<Identity> is the Data source file path of the DLL
<Encoding> can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
Example
[Collection: TSPLJsonPlugin]
Data Source : PlugIn JSON : DLLPluginExternalIntegration.dll
Input Parameter : ##SVCurrentCompany
Input JSON : CustomerDetailsReport
Break On : ERROR
In this example, the report CustomerDetailsReport generates the input JSON which is sent to the DLL. ##SVCurrentCompany value is passed as input parameter to the DLL. The JSON response received from the DLL is populated in the collection TSPLJsonPlugin. Break ON validates this response by checking if the string ERROR is present in the response received.
Plugin XML/AxPlugin XML
By using this attribute, we can invoke the DLL and convert the returned values into TDL objects for further processing. The value returned by the DLL is an XML. The type specification, in this case, is Plugin XML or AxPlugin XML. For DLL Objects, Plugin XML is used for C++ DLL, and for DLLs created in VB, VB.Net, etc. applications, AxPluginXML can be used. In this case, Identity is the Class Name.
Syntax
[Collection: <Collection Name>]
Data Source : Plugin XML : <Identity>[:<Encoding>]
[Collection: <Collection Name>]
Data Source : AxPlugin XML : <Identity>[:<Encoding>]
Where,
<Identity> is the Data source file path of the DLL
<Encoding> can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
Example:
[Collection: InputXMLCollection]
Data Source : AxPlugin XML : TestDLL.Class1
Input XML : PostReqRep, PreReqRep
In this example, the report PreReqRep first accepts the user input, and then it generates the input XML which is sent to the DLL. The XML response received from the DLL is populated in the collection InputXMLCollection.
JSON String & XML String
TDL supports the use of XML and JSON strings as direct data sources for populating collections.
This capability allows developers to streamline the handling of variable-based data and significantly improve efficiency in financial services projects and other data-intensive applications. By feeding structured data directly from string variables into a collection, developers can bypass intermediate steps like file creation or external HTTP calls.
Some of the key features are listed below:
- Direct Data Source Utilization
- XML and JSON Strings can now be used directly as data sources, eliminating the need for intermediary file handling steps.
- This update simplifies how you work with XML data, which you had to manage through complex workarounds before.
- Enhanced Efficiency
- This feature lets you handle JSON and XML strings with a separate data source, making it easier to manage variable-based data efficiently.
- Simplified Syntax
- Easily integrate XML and JSON data by passing them as parameters, without needing additional file operations.
Syntax: XML String
[Collection: <Collection Name>]
Data Source: XML String: <Identity/Data>
Syntax: JSON String
[Collection: <Collection Name>]
Data Source: JSON String: <Identity/Data>
Where,
<Identity/Data> In this case XML or JSON data given as direct string or formula that evaluates to a string.
Example for JSON String Data Source:
Direct String
[Collection: JSONGather1]
DataSource: JSONString :‘{“IsConnectivityError”:false,”ResponseCode”:200,”Response”:+
“message”:”Fetched successfully”,”data”:[{“applicationNumber”:”LA20240115000600″,+
“applicationName”:”Term Loan 1″,”applicationStatus”:”NW”,”applSubmissionComplete”:0,+
“createdAt”:”2024-01-15T07:57:08.000Z”,”updatedAt”:”2024-01-15T08:04:05.000Z”,+
“createdBy”:”911111111111″,”applicantMobile”:”911111111111″}]}}’
JSON Object Path : “Response:1”
System Formula
[Collection: JSONGather2]
Data Source : JSON String : @@JsonData
JSON Object Path : “Response:1”
System Variable
[Collection: JSONGather3]
Data Source : JSON String : ##SVJsonData
JSON Object Path : “Response:1”
Example for XML String Data Source:
Direct String
[Collection: XMLGather1]
Data Source : XML String : ‘<B2C_REPORT><REQUEST><NAME>MANISHA GOPALE</NAME> +
<PAN>GAURR0857M</PAN><EMAIL_1>abc@abc.com</EMAIL_1><ADDRESS_1></ADDRESS_1><ADDRESS_2>+
</ADDRESS_2><ADDRESS_3></ADDRESS_3><PHONE_1>8793564813</PHONE_1></REQUEST></B2C_REPORT>’
XML object path : “B2C_REPORT:1”
System Formula
[Collection: XMLGather2]
Data Source : XML String : @@XmlData
XML object path : “B2C_REPORT:1”
System Variable
[Collection: XMLGather3]
Data Source : XML String : ##SVXmlData
XML object path : “B2C_REPORT:1”
- You can set the XML String as the data source and supply the variable that contains the XML data.
- You can set the JSON String as the data source and supply the variable that contains the JSON data.
- If you supply an empty string, the output will be empty as expected.
- Providing an incorrect JSON or XML structure results in an empty output.
Remote URL
Remote URL attribute is used to specify the URL of the HTTP server delivering the XML data. The URL can be directly specified as string or through a String formula. This attribute is mandatory to access the data in XML format from remote server in a collection.
Syntax
[Collection:<Collection Name>]
Remote URL: <http-url formula>
Where,
< http-url formula > can be any string formula which resolves as an URL.
Example
The collection is created as follows to populate XML data available at the URL http://localhost/TestXML.xml:
[Collection: XML Get Collection]
Remote URL : “http://localhost/TestXML.xml”
This collection can be used in a TDL Report to display the data retrieved. To display the retrieved data the line is repeated over this collection.
Repeat: XMLDetLn : XMLGetCollection
In the field the XML TAG names are used as method names.
[Field: CustNm]
Set As : $NAME
To display the PHONE and ADDRESS details, the line can be exploded.
[Line : XMLDetLn]
Explode : PhPart
Explode : AddPart
In the Exploded parts the line is repeated over the PHONE and ADDRESS collection respectively.
[Part : PhPart]
Repeat : PhLine : PHONE
[Part: AddPart]
Repeat: AddLine : ADDRESS
Export Header
When you integrate TallyPrime with a third-party application, the communication can happen in a connected or non-connected environment where TallyPrime can act as a client or server or both.
In a connected environment, when communication happens over a network, TallyPrime can send GET or POST request to third-party applications and gather responses using collection capabilities. A GET request is always without a request body while a POST request has a request body. In both the cases, the request can have HTTP headers as required by the third-party and the HTTP standards.
To support this requirement, you can use the attribute, Export Header, to specify the HTTP headers when you send requests to HTTP servers.
Syntax
[Collection: <Collection Name>]
Export Header: <String Expression>
Where,
<Collection Name> is the name of the collection where the data is populated.
<String Expression>is a valid expression that evaluates to a string.
GET Requests with Headers
A GET request sent to a server can have HTTP headers. It will not have any request body.
To send a GET request to a server with HTTP headers, specify the server URL in the collection attribute, Remote URL or the data source HTTP JSON or HTTP XML and the headers with the attribute Export Header. The choice of the attribute for URL specification depends on the format of data exchange.
Syntax
[Collection: <Collection Name>]
Export Header: <String Expression>
Remote URL: <Target URL>
OR
[Collection: <Collection Name>]
Export Header: <String Expression>
Data Source: HTTPJSON/HTTPJSONEX/HTTPXML : <Target URL> [: <Encoding>]
Where,
<Collection Name> – the name of the collection where the data is populated.
<Target URL> – the URL to which the request is to be sent.
<Encoding> – can be ASCII, UNICODE, UNICODE8, UTF8, or UTF16. The default value is UTF16.
POST Requests with Headers
A POST request is sent to a server with request body and HTTP headers, where the headers are optional.
To send a POST request to a server with HTTP headers, specify the server URL in the collection attribute, Remote URL or the data source HTTP JSON or HTTP JSONEx or HTTP XML, and the headers with the collection and report attribute Export Header. To construct the request body use the attribute Request Report. When you specify the headers in both collection and the request report (using Export Header ), both the headers will be considered. The choice of the attribute for URL specification depends on the format of data exchange.
[Collection: <Collection Name>]
Remote URL : <Target URL>
Export Header : <String Expression>
Remote Request : <Request Report> [: <Encoding>]
OR
[Collection: <Collection Name>]
Data Source: HTTPJSON/HTTPJSONEX/HTTPXML : <Target URL> [: <Encoding>]
Export Header : <String Expression>
Remote Request : <Request Report> [: <Encoding>]
When you use the attribute Export Header you can observe the following:
- When multiple collections are used, like summary collection or union collection, specify the attribute Export Header in the collection where the attribute Data source is mentioned.
- In the case of POST request, the headers specified at collection and report levels will be part of the request sent. The order of adding headers in the request is first from the collection and then from the report.
- The attribute Export Header is applicable only when an HTTP source is specified using the attribute Remote URL or data sources like HTTP JSON or HTTP JSONEX or HTTP XML.
Example
Case 1 :Send a GET request with HTTP headers and receive the response
The HTTP header ” Accept:application/json ” is sent to the server, in order to receive the response in JSON format. Data source type HTTP JSON is used to exchange the data in JSON format.
[Collection: TSPL Get Employees JSON]
Export Header : “Accept:application/json”
Data Source : HTTP JSON: “http://localhost/ExportHeader/getempdetails.php” :UTF8
| Request Sent | Response Received |
|
Accept: application/json |
{ “employees”: {“employee”: [ { “Name”: “John Smith” }, { “Name”: “Jessica Jones” } ] } } |
Case 2: Send a POST request with HTTP headers and receive the response
In the request, Accept:application/xml , Emp Id as HTTP header, and Leave Type as body are sent to the server to receive the response in XML format for the selected employee and the leave type. Data source type HTTP XML is used to exchange data in the XML format.
[Collection: TSPLLeaveSummaryXML]
Data Source : HTTP XML: “http://localhost/ExportHeader/getleavedetails.php”
Export Header : “Accept:application/xml”
Export Header : “EmpId:5989”
RemoteRequest : TSPL Leave Request: UTF8
XML Object Path: “LeaveInfo:1:Envelope:LeaveDetails:1”
The request report, TSPL Leave Request is used to construct the request body.
| Request Sent | Response Received |
|
Accept: application/xml EmpId : 5989 <Request> <LeaveType> Earned Leave </LeaveType> </Request> |
<Envelope> <LeaveDetails> <Employee> Vamsi </Employee> <EmpId>5989</EmpId> <Gender>Female</Gender> <LeaveInfo> <Type>Earned Leave</Type> <Entitled>24</Entitled> <Availed>10</Availed> </LeaveInfo> </LeaveDetails> </Envelope> |
Remote Request
A TDL report can be sent to the HTTP server as an XML or JSON request, and the response is obtained in the collection. Remote Request attribute is used to specify the Report name which is sent to the HTTP server as an XML or JSON Request. If the report requires user inputs, then it must be accepted before the request is sent. Pre-request is used to specify the name of the report which accepts the user-input.
Syntax
[Collection: <Collection Name>]
Remote Request: <request-report-name>,<pre-request-report>: <encoding type>
Where,
<request-report-name > is the name of the TDL Report which will be used for generating XML or JSON Request to be sent.
<pre-request-report> is the name of the TDL Report which accepts the user-input.
< Encoding Type > specifies the encoding to be used while transmitting information to the receiving end. The valid encoding formats are ASCII, UNICODE, UNICODE8, UTF8, or UTF16. UNICODE is set by default.
This attribute is used along with collection attribute Remote URL or Datasource HTTP XML for XML data exchange and Datasource HTTP JSONEX or HTTP JSON for JSON data exchange
Example
Case1: XML Post
The Test.php page on the remote server accepts the data in the following XML format.
<ENVELOPE>
<REQUEST>
<NAME>Tally</NAME>
<EMPID>00000</EMPID>
</REQUEST>
</ENVELOPE>
Following collection sends request in the above XML format with the help of a TDL report XML-PostReqRep. The encoding scheme selected is ASCII.
[Collection: XML Post Collection]
Remote URL: “http://Remoteserver/test.php“
RemoteRequest : XMLPostReqRep : ASCII
The report XMLPostReqRep is automatically executed when the collection is referred.
Request Report
In the request report XMLPostReqRep , the XMLTag attribute is used at Part and Field Definitions. The XML Tag <ENVELOPE> is added by Tally while sending the XML request.
In the part definition the XML Tag is specified as “REQUEST”.
[Part: XMLPostReqRep]
XML Tag : “REQUEST”
Scroll : Vertical
In the field definitions the tag names “NAME” and “EMPID” are specified.
[Field: XMLPostReqRepName]
XML Tag : “NAME”
Set As : “Tally”
[Field: XMLPostReqRepId]
XML Tag : “EMPID”
Set As : “00000”
The response received from “http://Remoteserver/test.php” page is the same XML given previously. The data now available in the collection can be displayed in a TDL report.
Pre- request Report
A Pre-request report is required when some inputs are to be accepted from the user and the XML Request is to be generated out of those inputs. In that case, a TDL report is used which has to be accepted first. If the data captured through pre request report has to be sent to remote server for processing then it has to be made available in the Request Report. The input report name is specified as Pre Request Report.
[Collection: XML Post Collection]
Remote URL : “http://localhost/test.php”
RemoteRequest : XMLPostReqRep, XML PreReqRep : ASCII
The Report XMLPostReqRep sends the XML request to the page Test.php in the format described earlier. Before sending the XML request to the page, the data entered in the report XML PreReqRep must be accepted. The data entered in the Pre-Request report can also be sent to the remote server in the XML request. Both the reports are triggered when the collection is referred. PreRequest Report is only used to accept value from the user. These values are sent to the HTTP Server through the Request Report Only.
Case 2: JSON POST
The following code snippet sends a POST request to the URL mentioned with the branch name, and receives customer details of the branch, in JSON format.
[Collection: TSPLBranchCustomers]
Data Source: HTTP JSON: “http://localhost/HttpJson/branchcustomers.php“
Remote Request: TSPL Branch Customers: ASCII
[Report: TSPLBranchCustomers]
Form : TSPLBranchCustomers
……
……
[Field: TSPLBranchName]
Set As: “North“
JSON Tag : “Branch“
| Request Sent | Response Received |
|
{ “Branch“: “North“ } |
{ “Branch“: “North“, “Customer“: [ { “Name“: “Sapna Awasthi“, “State“: “Delhi“ }, { “Name“: “Ashish Rai“, “State“: “Delhi“ } ] } |
JSON Object Path/ XML Object Path
Collection attribute Data Source is used to populate JSON and XML data from external applications in the collection by specifying the appropriate type – HTTP JSONEx, HTTP JSON, File JSON, HTTP XML, FileXML, XML String, JSON String, Remote URL. While by default reading this data starts from the root node, it is possible that the actual data required for consumption starts from a different node in the response structure. In these cases, one can use the attribute JSON Object Path or XML Object Path to specify from which position in the response the data needs to be read. This attribute converts the extracted data fragment as a TDL object in the collection.
Syntax
[Collection: <Collection Name>
JSON Object Path :<StartNode>:<Path to start node>
OR
XML Object Path :<StartNode>:<Path to start node>
Where,
<StartNode> – the name of the starting JSON Node in case of JSON, XML Node in case of XML. The parameter is specified as <Node Name> : <Position>
<Path to Start Node> – the path of the starting JSON Node in case of JSON, XML Node in case of XML.
The structure is <Child Node> : <Start Pos> : <Child Node> : <Start Pos> …
In JSON, you cannot specify the root node because the root node is unnamed.
While specifying the tag names in the attribute, the case should be as per the tag specified in the XML/JSON response. Make sure value is written within quotes.
XML Object Path and JSON Object Path are aliases of each other. i.e. specify any of them in the collection and it will be applicable to the response data irrespective whether its XML or JSON.
This attribute is used along with collection attributes that is used to read XML or JSON data like Remote URL and all the HTTP based, file based and Plugin based Data Source types.
Example XML
[Collection: TSPL Get Employees XML]
Export Header : “Accept:application/xml”
Export Header : “Accept-Charset:utf-8”
Data Source : HTTP XML:”http://localhost/ExportHeader/getempdetails.php”:UTF8
XML Object Path: “employee:1:employees”
This is an XML Get request with the http headers to fetch the employee details from the url. And the starting point of reading the response is given in XML Object Path attribute which is to read from the first employee tag within the employees tag
Response
<employees>
<employee>
<Name>Rashmi Reddy</Name>
<Department>Marketing</Department>
<Gender>Female</Gender>
<EmpId>5989</EmpId>
</employee>
<employee>
<Name>John Fernandes</Name>
<Department>RnD</Department>
<Gender>Male</Gender>
<EmpId>5145</EmpId>
</employee>
</employees>
Example JSON
The following code snippet sends a GET request to the URL mentioned and receives list of branches as a response in JSON format. And the starting point of reading the response is given in JSON Object Path attribute which is to start from first object of Branchname array.
[Collection: TSPLGetBranchesColl]
Data Source : HTTP JSON: “ http://localhost/HttpJson/getbranchlist.php“
JSON Object Path: “BranchName:1“
The response in JSON format.
{
“BranchName“:
[
“East“,
“North East“,
“North“,
“West“,
“South“
]
}
JSONObject/ XML Object
The JSON or XML data being collected in the collection, is by default converted automatically to TDL objects and is available natively for consumption as $ based methods. The TDL Objects are created with same Names as the tags received in the data. For better understanding and usage, one might want to define the whole structure with meaningful object and method names. In this case, the attribute XML Object alias JSON Object is used to map the user defined TDL object name to the XML or JSON data being read.
Syntax
[Collection: <Collection Name>]
XMLObject : <TDL-Object-Name>
Where,
< TDL-Object-Name > is user defined name. The data is required to be mapped as TDL Objects. The following syntax is used for object specification:
[Object: <Object Name>]
Storage : <Name> : <Type>
Collection : <Name> : <Type>
The second parameter in the Collection type can be an Object type in case of a complex collection or a simple data type in case of simple collection.
When you read JSON or XML Data you can observe the following features:
- The leaf values are available as methods in the collections, and the JSON/XML tags are the method names.
- In case TDL Object is used for mapping the JSON/XML Object, only the method/storage, collection defined within the TDL Object will be gathered from the XML/JSON data.
- While JSON and XML allow an object to have another object directly under it, this is not allowed in the Tally Object structure. Hence, this translates to a collection within the current object having a single object. The name of this sub collection will be the name of the object member in the source file.
XML Object and JSON Object are aliases of each other. i.e. specify any of them in the Collection and it will be applicable to the response data irrespective whether its XML or JSON.
This attribute is used along with collection attributes that is used to read XML or JSON data like Remote URL and all the HTTP based, file based and Plugin based Datasource types.
Example XML
The data available in XML format is at the URL “http://Remoteserver/TestXML.xml”.
<CUSTOMER>
<NAME> Sapna Awasthi</NAME>
<EMPID>1000 </EMPID>
<PHONE>
<OFFICENO>080-66282559</OFFICENO>
<HOMENO>011-22222222</HOMENO>
<MOBILE>990201234</MOBILE>
</PHONE>
<ADDRESS>
<ADDRLINE>C/o. Info Solutions</ADDRLINE>
<ADDRLINE>Technology Street</ADDRLINE>
<ADDRLINE>Tech Info Park</ADDRLINE>
</ADDRESS>
</CUSTOMER>
The collection attribute XML Object is used to specify the object name to which the obtained data is mapped.
[Collection: XML Get Collection]
Remote URL : “http://Remoteserver/TestXML.xml”
XML Object : Customer Data
The Object specification for “Customer Data” is as follows:
[Object: Customer Data]
Storage : Name : String
Storage : EmpId : String
;;Complex collections
Collection : Phone : XML Phone Coll
Collection : ADDRESS : XML AddressColl
[Object: XML Phone Coll]
Storage : OfficeNo : String
Storage : HomeNo : String
Storage : Mobile : String
[Object: XML AddressColl]
Collection : AddrLine : String ;; Simple collection
Example JSON
{
“Vch”: [
{
“Vch Num”: “1”,
“Vch Dt.”: “1-Apr-2017”,
“items”: [
{
“Stock Item”: “Item1”,
“Qty”: “100 Nos”
},
{
“Stock Item”: “Item2”,
“Qty”: “40 Nos”
},
{
“Stock Item”: “Item3”,
“Qty”: “25 Nos”
}
]
},
{
“Vch Num”: “1”,
“Vch Dt.”: “1-Apr-2017”,
“items”: [
{
“Stock Item”: “Item1”,
“Qty”: “500 Nos”
},
{
“Stock Item”: “Item2”,
“Qty”: “300 Nos”
},
{
“Stock Item”: “Item3”,
“Qty”: “450 Nos”
}
]
}
]
}
Read the data fragment and map them to the user defined TDL Object.
[Collection: TSPLJSONFileColl]
Data Source: FileJSON : “DataFile.Json”
JSON Object: VoucherData
[Object: VoucherData]
Collection : Vch : Vouchers
[Object: Vouchers]
Storage : Vch Num : String
Storage : Vch Dt. : Date
Collection : Items : Items Coll
[Object: ItemsColl]
Storage : Stock Item : String
Storage : Qty : Quantity
Input JSON / Input XML
When integrating with DLL where data exchange is either JSON or XML, the input XML or JSON is given to the DLL using the attribute Input JSON or Input XML. This parameter is used in combination with the Datasource attribute in the collection where the Type can be Plugin JSON / Plugin XML / Ax Plugin XML
Syntax
[Collection: <Collection Name>]
Input JSON : <Post Request Report Name>, <Pre-Request Report Name>
Where,
<Post Request Report Name> is the name of the TDL report. It is responsible for generating XML/JSON data, which is passed to the DLL function as input
<Pre-Request Report Name> is optional. It is used to get user input, which is used in the post request report.
Input JSON and Input XML are aliases of each other. i.e. specify any of them in the Collection and it will be used to pass the input to the DLL. The type of input, i.e. JSON or XML depends on the plugin type specified in the Datasource attribute.
Example XML
[Collection: InputXMLCollection]
Data Source : AxPlugin XML : TestDLL.Class1
Input XML : PostReqRep, PreReqRep
In this example, the report PreReqRep accepts the user input, and the report PostReqRep generates the input XML which is sent to the DLL. The XML response received from the DLL is populated in the collection InputXMLCollection.
Example JSON
[Collection: TSPLJsonPlugin]
Data Source : PlugIn JSON : DLLPluginExternalIntegration.dll
Input Parameter : ##SVCurrentCompany
Input JSON : CustomerDetailsReport
Break On : ERROR
In this example, the report CustomerDetailsReport generates the input JSON which is sent to the DLL. ##SVCurrentCompany value is passed as input parameter to the DLL. The JSON response received from the DLL is populated in the collection InputXMLCollection. Break ON validates this response by checking if the string ERROR is present in the response received.
Input Parameter
The attribute Input Parameter is used to pass a single string value to the DLL function. This parameter is used in combination with the Datasource attribute in the collection where the Type can be Plugin JSON / Plugin XML / Ax Plugin XML
Syntax
[Collection: <Collection Name>]
Input Parameter: <Expression>
Where,
<Expression> returns a string value, which is used to pass to the DLL function.
Example
[Collection: TSPLJsonPlugin]
Data Source : PlugIn JSON : DLLPluginExternalIntegration.dll
Input Parameter : ##SVCurrentCompany
Input JSON : CustomerDetailsReport
Break On : ERROR
In this example, the report CustomerDetailsReport generates the input JSON which is sent to the DLL. ##SVCurrentCompany value is passed as input parameter to the DLL. The JSON response received from the DLL is populated in the collection TSPLJsonPlugin. Break ON validates this response by checking if the string ERROR is present in the response received.
Break on
The attribute Break On is used to validate the JSON or XML data received from the DLL function. If the JSON or XML data contains the string specified in the attribute which is referred as error string, then the validation fails, and the collection will not be gathered. A common use case is to specify error code as parameter. This parameter is used in combination with the Datasource attribute in the collection where the Type can be Plugin JSON / Plugin XML / Ax Plugin XML
Syntax
[Collection: <Collection Name>]
Break On : <String Expression1>, <String Expression 2>…..
Where,
<String Expression 1>, <String Expression 2>… gives the string values which act as error string to validate the JSON or XML data.
Example
[Collection: TSPLJsonPlugin]
Data Source : PlugIn JSON : DLLPluginExternalIntegration.dll
Input Parameter : ##SVCurrentCompany
Input JSON : CustomerDetailsReport
Break On : ERROR
In this example, the report CustomerDetailsReport generates the input JSON which is sent to the DLL. ##SVCurrentCompany value is passed as input parameter to the DLL. The JSON response received from the DLL is populated in the collection TSPLJsonPlugin. Break ON validates this response by checking if the string ERROR is present in the response received.
