Implement custom data adapter for http post requests

Stimulsoft Reports.JS discussion
Post Reply
jaqb
Posts: 23
Joined: Thu Jul 25, 2024 7:09 am

Implement custom data adapter for http post requests

Post by jaqb »

Hello, I am trying to implement custom data adapter which allows me to get data with http 'post' request.
I would like to enter the URL as the connection string in the Stimulsoft editor, then process this url and then send the http request using axios. This mechanism works almost correctly so far, but the problem is that the retrieveData is triggered for each table in the data source so if I have nested objects, the request is repeated for each this object. How can I set it up so that it sends only one request and the tables for nested objects are determined based on the result of the request for the root element?


My data adapter look like this so far:

Code: Select all

	{
		serviceName: "POST",
		sampleConnectionString: "",
		
		process: (command, callback) => {
			switch(command.command) {
				case "TestConnection": {
					testConnection(command);
					callback({ success: false, notice: "Error" });
					break;
				}

				case "RetrieveSchema": {
					const data = retrieveSchema(command).then(resp => {
						callback({ success: true, data: resp.data });
					});
					break;
				}
				case "RetrieveData": {
					retrieveData(command).then(resp => {
						callback({ success: true, data: resp.data });
					});
					break;;
				}
			}
		}
	}
	
	...
	
	function retrieveSchema(command) {
		return retrieveData(command)
	}
	
	function retrieveData(command) {
		const url = command.connectionString;
		...
		return axios.get(url);
	}
jaqb
Posts: 23
Joined: Thu Jul 25, 2024 7:09 am

Re: Implement custom data adapter for http post requests

Post by jaqb »

I have another problem. How can I get the current values ​​of variables entered by the user with input controls? If I use stiReport.dictionary.variables, these variables do not update with the changes made by the user
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Implement custom data adapter for http post requests

Post by Lech Kulikowski »

Hello,

Please check the following article:
https://github.com/stimulsoft/DataAdapters.JS

Thank you.
jaqb
Posts: 23
Joined: Thu Jul 25, 2024 7:09 am

Re: Implement custom data adapter for http post requests

Post by jaqb »

Thank you for your reply.
I have already read this article. Maybe I confused custom data adapter with custom database (I based my solution on this sample: https://github.com/stimulsoft/Samples-R ... apter.html).
Nevertheless, I need to send one custom HTTP POST request from javascript code to the REST server and then insert received data into data source tables. I am able to get the data with data adapter but the problem is that for each data source table the code defined in the custom adapter is repeated. I want to execute data adapter code only once and insert the received data into the data source tables.
jaqb
Posts: 23
Joined: Thu Jul 25, 2024 7:09 am

Re: Implement custom data adapter for http post requests

Post by jaqb »

My main problem is that I need to send a large number of request parameters (a list of object ids selected with multiselect), making the length of the GET request exceed 2000 characters and there is a problem with it. Alternatively, can you suggest other solutions?
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Implement custom data adapter for http post requests

Post by Lech Kulikowski »

Hello,

There are no other solutions. You can implement your own data adapter as you need.

Thank you.
jaqb
Posts: 23
Joined: Thu Jul 25, 2024 7:09 am

Re: Implement custom data adapter for http post requests

Post by jaqb »

I have solved most of problems described earlier.
Now I have a problem with retrieving user input variables from the code level for the report in the designer mode. I get variables via window[“stiReport”].dictionary.variables.list and in the designer mode these variables values are equal empty string even though they should have set values. In viewer mode everything is fine.
How can I solve this problem?
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Implement custom data adapter for http post requests

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
Post Reply