Need a special offer?Find out if your project fits.
+

How to save a report with the correct structure in a server

Answered
Jonatan asked on June 20, 2024

I have to save a report in a repository and generate an url link to the server, now y save the json file in my db and have the follow structure:

{"name": "Prueba reporte HSEQ", "type": "json", "report": {"slice": {"rows": [{"uniqueName": "f"}, {"uniqueName": "p"}], "columns": [{"uniqueName": "a"}, {"uniqueName": "q"}, {"uniqueName": "m"}, {"uniqueName": "[Measures]"}], "measures": [{"uniqueName": "dis", "aggregation": "sum"}, {"uniqueName": "hw", "aggregation": "sum"}, {"uniqueName": "cm", "aggregation": "sum"}, {"uniqueName": "mv", "aggregation": "max"}]}, "options": {"grid": {"showTotals": "off", "showGrandTotals": "off"}}, "version": "2.9.79", "conditions": [{"format": {"color": "#FFFFFF", "fontSize": "12px", "fontFamily": "Arial", "backgroundColor": "#DA3230"}, "formula": "#value > 80", "measure": "mv"}, {"format": {"color": "#FFFFFF", "fontSize": "12px", "fontFamily": "Arial", "backgroundColor": "#799E0F"}, "formula": "#value <= 80", "measure": "mv"}], "dataSource": {"type": "json", "mapping": {"a": {"caption": "Año"}, "d": {"caption": "Fecha y hora"}, "f": {"type": "string", "caption": "Flota"}, "m": {"caption": "Mes"}, "p": {"type": "string", "caption": "Placa"}, "q": {"caption": "Trimestre"}, "ac": {"type": "number", "caption": "Aceleraciones bruscas"}, "cm": {"type": "number", "caption": "Combustible consumido"}, "co": {"caption": "Conductor"}, "di": {"caption": "Dia"}, "ev": {"type": "number", "caption": "Excesos de velocidad"}, "fr": {"type": "number", "caption": "Frenadas bruscas"}, "gr": {"caption": "Grupo"}, "hw": {"type": "number", "caption": "Horas trabajadas"}, "id": {"type": "false"}, "mv": {"type": "number", "caption": "Máxima velocidad"}, "ra": {"type": "number", "caption": "Ralenti"}, "ri": {"type": "number", "caption": "Trayectos"}, "dis": {"type": "number", "caption": "Distancia"}, "idl": {"type": "number", "caption": "IDLE"}}, "filename": "https://web1.co/DOC/PivotTable/basic.json"}, "creationDate": "2024-06-20T13:41:21.138Z"}}

 

but this json don't fit the structure to load the report in the grid, I load a manual json on my server and call it from my bd, and works well, but this json have the structure of a archive when it save local, like this:

 

{
"dataSource": {
"type": "json",
"filename": "https://web1.co/DOC/PivotTable/basic.json",
"mapping": {
"f": {
"caption": "Flota",
"type": "string"
},
"p": {
"caption": "Placa",
"type": "string"
},
"a": {
"caption": "Año"
},
"q": {
"caption": "Trimestre"
},
"m": {
"caption": "Mes"
},
"dis": {
"caption": "Distancia",
"type": "number"
},
"hw": {
"caption": "Horas trabajadas",
"type": "number"
},
"cm": {
"caption": "Combustible consumido",
"type": "number"
},
"mv": {
"caption": "Máxima velocidad",
"type": "number"
},
"ac": {
"caption": "Aceleraciones bruscas",
"type": "number"
},
"fr": {
"caption": "Frenadas bruscas",
"type": "number"
},
"ev": {
"caption": "Excesos de velocidad",
"type": "number"
},
"gr": {
"caption": "Grupo"
},
"idl": {
"caption": "IDLE",
"type": "number"
},
"ra": {
"caption": "Ralenti",
"type": "number"
},
"d": {
"caption": "Fecha y hora"
},
"co": {
"caption": "Conductor"
},
"di": {
"caption": "Dia"
},
"ri": {
"caption": "Trayectos",
"type": "number"
},
"id": {
"type": "false"
}
}
},
"slice": {
"rows": [
{
"uniqueName": "f"
},
{
"uniqueName": "p"
}
],
"columns": [
{
"uniqueName": "a"
},
{
"uniqueName": "q"
},
{
"uniqueName": "m"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [
{
"uniqueName": "dis",
"aggregation": "sum"
},
{
"uniqueName": "hw",
"aggregation": "sum"
},
{
"uniqueName": "cm",
"aggregation": "sum"
},
{
"uniqueName": "mv",
"aggregation": "max"
}
]
},
"options": {
"grid": {
"showTotals": "off",
"showGrandTotals": "off"
}
},
"conditions": [
{
"formula": "#value > 80",
"measure": "mv",
"format": {
"backgroundColor": "#DA3230",
"color": "#FFFFFF",
"fontFamily": "Arial",
"fontSize": "12px"
}
},
{
"formula": "#value <= 80",
"measure": "mv",
"format": {
"backgroundColor": "#799E0F",
"color": "#FFFFFF",
"fontFamily": "Arial",
"fontSize": "12px"
}
}
],
"version": "2.9.79",
"creationDate": "2024-06-20T15:58:48.964Z"
}

 

Can you give me an example of how save in the server the data like this and not the other format?

7 answers

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 21, 2024

Hello, Jonatan!

Thank you for reaching out to us.

Kindly note that the report in the provided JSON object seems to match our structure. Here is the structure of our Flexmonster report JSON object for reference: https://www.flexmonster.com/api/report-object/.

Could you please provide us with more details about your use case? For example, how are you creating a Flexmonster instance and setting the report to it? Also, on which condition the report should be sent to the server and restored from it?

With this information, we'll be able to provide you with more specific suggestions.

Looking forward to hearing from you.

Kind regards,
Solomiia

Public
Jonatan June 21, 2024

When I save the report to the server on the db, I have this json:

'{"name": "report.json", "type": "json", "report": {"slice": {"rows": [{"uniqueName": "f"}, {"uniqueName": "co"}], "columns": [{"uniqueName": "a"}, {"uniqueName": "q"}, {"uniqueName": "m"}, {"uniqueName": "[Measures]"}], "measures": [{"uniqueName": "ac", "aggregation": "sum"}, {"uniqueName": "fr", "aggregation": "sum"}, {"uniqueName": "ev", "aggregation": "sum"}, {"uniqueName": "ra", "aggregation": "sum"}]}, "options": {"grid": {"showTotals": "off", "showGrandTotals": "off"}}, "version": "2.9.79", "conditions": [{"format": {"color": "#FFFFFF", "fontSize": "12px", "fontFamily": "Arial", "backgroundColor": "#DA3230"}, "formula": "#value > 80", "measure": "mv"}, {"format": {"color": "#FFFFFF", "fontSize": "12px", "fontFamily": "Arial", "backgroundColor": "#799E0F"}, "formula": "#value <= 80", "measure": "mv"}], "dataSource": {"type": "json", "mapping": {"a": {"caption": "Año"}, "d": {"caption": "Fecha y hora"}, "f": {"type": "string", "caption": "Flota"}, "m": {"caption": "Mes"}, "p": {"type": "string", "caption": "Placa"}, "q": {"caption": "Trimestre"}, "ac": {"type": "number", "caption": "Aceleraciones bruscas"}, "cm": {"type": "number", "caption": "Combustible consumido"}, "co": {"caption": "Conductor"}, "di": {"caption": "Dia"}, "ev": {"type": "number", "caption": "Excesos de velocidad"}, "fr": {"type": "number", "caption": "Frenadas bruscas"}, "gr": {"caption": "Grupo"}, "hw": {"type": "number", "caption": "Horas trabajadas"}, "id": {"type": "false"}, "mv": {"type": "number", "caption": "Máxima velocidad"}, "ra": {"type": "number", "caption": "Ralenti"}, "ri": {"type": "number", "caption": "Trayectos"}, "dis": {"type": "number", "caption": "Distancia"}, "idl": {"type": "number", "caption": "IDLE"}}, "filename": "https://web1.shareservice.co/DOC/ApiPivotTable/HSEQbasico.json"}, "creationDate": "2024-06-20T13:37:55.851Z"}}', but When I read that json, the report don't show in the grid. Can I save a file in the server with the same structure like the json file when I download the local report? I use load and open function but none of them works when I load the report from the db

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 24, 2024

Hello, Jonatan!

Thank you for getting back to us.

Please note that when saving the report to the server, the JSON sent to the server contains the following properties:

  • name "name": "report.json"
  • type "type": "json"
  • report "report": {"slice":...}

So, the provided JSON contains the correct report, but this report needs to be extracted from the JSON object, e.g., as yourJson.report or yourJson['report'].
This can be done:

  • before you save the report to the database. This way, only the report object would be saved in the database.
  • when reading the report from the database and sending it to the client side.

Hope you will find our answer helpful.
Please let us know if everything works well now.

Kind regards,
Solomiia

Public
Jonatan June 24, 2024

Thanks,

Can you give me an example, I'm new using flexmonster, I see examples in jsfiddle in some answers, and try to do it, but in this case, I don't understand how to load the json in the db and set as a report.

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 24, 2024

Hello, Jonatan!

Thank you for your swift response.

Please note that in the JSFIddle, we are limited to showing only the client-side logic, which may differ from the one you have when loading a report from the server. Our team has prepared a JSFIddle example of loading the JSON you provided into Flexmonster, showing how the client part can be configured: https://jsfiddle.net/flexmonster/Levnjz91/. Please check out the comments I left in the code.

Regarding your question about how to save JSON into a database, the approach depends on the technologies you use on your server. As a client-side component, Flexmonster sends a JSON object with all necessary data to the server, and all server-side logic should be implemented on your own.

Hope it helps. If no, please provide us with the code snippets showing how you are saving the report to the server and loading it to Flexmonster again. This information would help us greatly to continue the investigation.

Kind regards,
Solomiia

Public
Jonatan June 25, 2024

Hi, thanks for the answer, I resolve the issue that I have, adapting the code you give me to the proyect, thanks.

Public
Solomiia Andrusiv Solomiia Andrusiv Flexmonster June 26, 2024

Hello, Jonatan!

Thank you for your feedback.

We are glad to hear that our example was helpful.

Feel free to reach out to us if any other questions arise.

Kind regards,
Solomiia

Please login or Register to Submit Answer