Report with JSON in AB1


Andrea

Hello Pablo and everybody,

I have a difficulty with reading a json file with direct reading in the url.

The json have this structure (SAMPLE): Inside the report I can get the field ' status' -> [Record.status], but not the meta_data [1].value: 'Italy', what is the correct syntax?

[Record.meta_data [1].value] is clearly an error.

I'd like to find a quick and straightforward solution, without making an HTTP request

Thank you


DecSoft

Hello Paolo,

I am wrong or you are using AB1, that is, the previous generation of DecSoft App Builder and not the current one?



Andrea
Yes, correct, testing with AB1

DecSoft

Hello Paolo,

First of all, what a [Report.Data] variable expected is an Array, not an Object. This means that the above JSON sample cannot be passed directly into a [Report.Data] variable. Supposing the above JSON is just a sample and what you have is really an Array, that is, something like below:

... then certainly you can place something like the below in the Report HTML property:

As you can see, first we can access to the "[Record.status]". Then every "Record" has a property named "meta_data", which is an Array. So we can use the "ng-repeat" directive in order to iterate over all the "meta_data" items properties.

However, I am not sure if you want to iterate and show all the items in the "Record.meta_data" Array, or just specifically one item of the "Record.meta_data" Array. In case that you want to only show one specific item of the "Record.meta_data" Array, the below HTML code in the Report HTML property allows to do that:

Certainly it's a bit complex, but, the logic is more or less clear. In the above case we only show the first element (index = 0) of the "Record.meta_data" Array. So please, carefully read this post and made your own tests, then you can post here any questions or doubts that you can have and I will try to help you, Paolo.

P.S. Remember, on the other hand, that the previous generation of DecSoft App Builder is not recommended for new projects: if you are developing a new project, my recommendation is to use the current generation of the product instead.



DecSoft

Hello again Paolo,

Supposing your JSON is certainly an Object and not an Array, then you can always use an HTML control instead a Report control. You can place a HTML control in your app view, and, in the Show event of that view, you can use a "SimpleGet" action like below:

... doing that the JSON Object will be in the "[JsonSource]" variable, so, inside the "html" property of the HTML control, you can prepare a code like below:

As you can see the code is very similar to the suggested before for a Report control. The point here is that your JSON is an Object, not an Array, so you cannot use a Report control, since the [Report.Data] variable expected an Array and not an Object.

So with this post I want to show you how it's also possible to use the JSON that you put as a sample "as is", without the need to convert it to an Array, in case that your JSON are an Object and not an Array. I hope this information can help you in some way too. And anyway, post here if you have any questions or doubts and I will try to help you.



Andrea

Wonderful, you were (AS ALWAYS) just perfect, now everything is clear.

to complete I now need to understand how to show in an alert (for example) of the field with the row click event (is possible without StartJS?)

the field is this:

PS: I hope soon to get back to studying the new generation, the missing ACTION menu, has always discouraged me a lot :(. But I am convinced, without even needing to be convinced, that to choose this path you will have evaluated well. If my teacher shows me the way, I have to want to follow it or not! Thanks again David, you are an example of how a business needs to be run, with extremely exceptional and friendly support


DecSoft

Hello Paolo,

First of all thanks for your kindly words. Inside the "RowClick" event we have the "ReportName.Record" variable, which contains the object which correspond with the row clicked in the Report control. So, for example, we can codify something like below in the "RowClick" event:

... the above show us the "status" property of the clicked "Record". We can also reach any other property of the Object, like the "meta_data" one, but in this case this property is an Array, so, we can codify something like below:

... in order to show the first item "value" property of the "meta_data" Array. Or we can iterate over all the "meta_data" items if we wanted:

So the key is that in the "RowClick" event we have the "ReportNameHere.Record", variable, which store the Object / row clicked by the user. Of course "ReportNameHere" must be replaced by the name of your Report control.

P.S. Certainly the current generation of AB do not have "visual actions", but, this do not mean that the IDE code editor don't help you with the Editor Quick Code List. The new generation of DecSoft App Builder (currently available) is better than the first one in too many aspect, Paolo. Certainly the "visual actions" are not offered, but, the new IDE offers help too, and, if you think twice, the directly usage of Javascript is like a "bonus", to say like that: no matter the number of possible "visual actions", we can't never reach the power of Javascript itself: for this reason AB1 includes the "StartJS" and the "EndJS" actions, because only with actions we can't get all the power of Javascript.



Andrea
Thats'all! works great, thanks! for the rest I have to go back to studying, without getting discouraged! Thanks

DecSoft

Always thanks you, sir! :-)


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.