Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html widget using a Expression with $query() isn´t able to display values from the query #175

Closed
ralfhennig opened this issue Jun 30, 2022 · 2 comments
Assignees
Milestone

Comments

@ralfhennig
Copy link

My query works fine, but the html widget doesnt show the results in html.
My query is: $query("RicohInvoices", "validContractsBySiteIdWithDoclink", { "SiteId" : pk1, "ContractStatus" : "active"})
The displayed result under the expression shows correct data:
[
{
"Contracts.ContractID": "0123456789",
"Contracts.Status": "active",
"Contracts.ValidFrom": "2014-12-01",
"Contracts.ValidUntil": null,
"Contracts.Note": "3x SP4310N",
"Contracts.yearlyRentalCosts": 123,
"NumberOfDevices": 3,
"Contracts.DocLink": "https://mydocURL"
...
The html source I use:
<% for (i of context) { %>

<% } %> Although the backticks are used for the properties with "." the widget doesn´t show any result.

If I change over to a $all() function to retrieve data, the results come without the table.colum syntax but just column and it is no problem to show the result in the html widget.
I am pretty sure it is a bug of the widget because escaping with backticks ` doesn work.

@aeberhart
Copy link
Contributor

Ok, this is a bit tricky. The $query function generates JSON objects with special characters (the dot):

In the JSONata expression, we escape using the backticks:

{
  "Contracts.DocLink": "https://mydocURL"
}.`Contracts.DocLink`

Contracts.DocLink selects "https://mydocURL" from the object

So far so good. In the HTML template, we're using EJS: https://ejs.co/ which allows generating HTML using JavaScript templates like <%= javascript %>.

In JavaScript, escaping field names works differently by using: object["field with special char"]:
https://stackoverflow.com/questions/12953704/how-can-i-access-object-properties-containing-special-characters

Long story short: this should work:

<% for (i of context) { %>
<%=i.["Contracts.ContractID"] %>
<% } %>

@aeberhart
Copy link
Contributor

please also see the new FAQ entry: #179

@aeberhart aeberhart self-assigned this Jul 13, 2022
@aeberhart aeberhart added this to the 2.5 milestone Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants