Page 1 of 1

Implement custom data adapter for http post requests

Posted: Thu Oct 24, 2024 9:32 am
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);
	}

Re: Implement custom data adapter for http post requests

Posted: Thu Oct 24, 2024 10:50 am
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

Re: Implement custom data adapter for http post requests

Posted: Fri Oct 25, 2024 7:31 am
by Lech Kulikowski
Hello,

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

Thank you.

Re: Implement custom data adapter for http post requests

Posted: Tue Oct 29, 2024 8:41 am
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.

Re: Implement custom data adapter for http post requests

Posted: Tue Oct 29, 2024 10:16 am
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?

Re: Implement custom data adapter for http post requests

Posted: Wed Oct 30, 2024 8:58 am
by Lech Kulikowski
Hello,

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

Thank you.

Re: Implement custom data adapter for http post requests

Posted: Wed Oct 30, 2024 9:19 am
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?

Re: Implement custom data adapter for http post requests

Posted: Thu Oct 31, 2024 8:06 pm
by Lech Kulikowski
Hello,

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

Thank you.