Problem generating PDF with POST and JSON input object.

29 views
Skip to first unread message

Pedro Carvalho

unread,
Dec 7, 2016, 6:29:15 AM12/7/16
to floreysoft
Hi all,

i'm new to this tool, but i'm invoking a Ultradox project based on a Google Docs Document with some placeholders. And thos simple place holders ${test} work well with the JSON i send.

The issue is with arrays properties that i would like to iterate.

Here goes an example, my JSON input is this:

{
"readingsTableHeaders": [{"header": "H1"}, {"header": "H2"}, {"header": "H3"}],
"name" : "Daniel",
"authors" : [
{
"name" : "Arnon Grunberg",
"books" : [
{
"title" : "Mit Haut und Haaren",
"published" : "2012"
},
{
"title" : "Tirza",
"published" : "2006"
}
]
},
{
"name" : "Fjodor Michailowitsch Dostojewski",
"books" : [
{
"title" : "Schuld und Sühne",
"published" : "1864"
},
{
"title" : "Die Brüder Karamasow",
"published" : "1877"
}
]
}
]
}
And in the GDocs i have this logic (tried many variations so far):

${foreach to.readingsTableHeaders headerObj}
${headerObj.col1}
${end}

And from the Help examples (i know its html, but i want only to prove the concept) ,and then go from there:

${foreach authors author}
<h2>Your books from ${author.name}</h2>
<table>
<!-- ... and display all books by this author -->
${foreach author.books book}
<tr><td>${book.title}</td><td>${book.published}</td></tr>
${end}
</table>
${end}

But nothing happens..

I tried putting this JSON data directly on Ultradox Project variables, but it gives me an JavaScript Native Array.. error..

What am i doing wrong with the arrays part?

Thanks in advance.

Pedro Carvalho

Daniel Florey

unread,
Dec 7, 2016, 6:36:06 AM12/7/16
to floreysoft GmbH
In your example you should use this syntax:
${foreach to.readingsTableHeaders headerObj}
${headerObj.header}
${end}

Hope this helps

--
You received this message because you are subscribed to the Google Groups "floreysoft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to floreysoft+unsubscribe@googlegroups.com.
To post to this group, send email to flore...@googlegroups.com.
Visit this group at https://groups.google.com/group/floreysoft.
For more options, visit https://groups.google.com/d/optout.

Pedro Carvalho

unread,
Dec 7, 2016, 7:32:09 AM12/7/16
to flore...@googlegroups.com
Hi Daniel,

Many thanks for answering my questions.

Ah that 'col1' was a typo, from a previous example i tried before, sorry.

I generated a new GDocs very simple, with only your code written:

${foreach to.readingsTableHeaders headerObj}
${headerObj.header}
${end}

And i'm invoking the template with this JSON data:

{
    "readingsTableHeaders": [{"header": "H1"}, {"header": "H2"}, {"header": "H3"}]
}

And no results appear :( 

Also tried to put the array directly in the project variable like this:

[{"header": "H1"}, {"header": "H2"}, {"header": "H3"}]

And in the preview also no result appear in the generated document.

I think i'm missing something very simple, but i'm stuck..

Thanks, in advance for your help.

Best Regards,
Pedro Carvalho 


--
You received this message because you are subscribed to a topic in the Google Groups "floreysoft" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/floreysoft/WNV8HsY2KJ0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to floreysoft+unsubscribe@googlegroups.com.

To post to this group, send email to flore...@googlegroups.com.
Visit this group at https://groups.google.com/group/floreysoft.
For more options, visit https://groups.google.com/d/optout.



--
Os melhores cumprimentos,
Pedro Carvalho

Daniel Florey

unread,
Dec 8, 2016, 4:36:02 AM12/8/16
to floreysoft GmbH
Hi Pedro,
how are you passing the data to your Ultradox flow?
Are you using a webhook to read it from somewhere or are you sending it as post body of your request?
Looks like Ultradox does not get it...

Thanks,
Daniel

Pedro Carvalho

unread,
Dec 8, 2016, 8:22:31 PM12/8/16
to flore...@googlegroups.com
Hello Daniel,

The data is passing with a POST call on the Ultradox project with this JSON, with a smallest and simple example:

{
 "testVar": "PlaceHolder Text appears",
 "readingsTableHeaders": [{"header": "H1"}, {"header": "H2"}, {"header": "H3"}]
}

The code in the GDocs template is as such:

Simple placeholder test:


-> ${testVar}


Loop test:


${foreach to.readingsTableHeaders headerObj}

${headerObj.header}

${end}


And the produced PDF is in the attachment i send you.

As you can see, the value of property 'testVar' is written in it's place.

But the array of readingsTableHeaders is not :(

I will analyse in detail the post data with WireShark, to see possible problems, but it's strange some variables are being filled correctly and other aren't.

Thank you very much.

Best regards,
Pedro Carvalho

RPE_electricidade_20161209003120.pdf

Daniel Florey

unread,
Dec 9, 2016, 3:07:33 AM12/9/16
to floreysoft GmbH
What is the to. prefix before the variable? You shoud just use


${foreach readingsTableHeaders headerObj}

${headerObj.header}

${end}


in your case...

Pedro Carvalho

unread,
Dec 9, 2016, 7:00:23 AM12/9/16
to flore...@googlegroups.com
Hi Daniel,

yes, that was a question i had for you too lol

In the first response you sent me (and in some of your examples) you have the prefix 'to.' also (but the problem is that i sent you that example wrongly, sorry). I didn't undertood what it was when first reading the examples on your site, but when i saw it, i tried everything.

I had already tried (before i sent you the email) without the 'to.' prefix and the result was the same.

 Ok, but just now i figured out what i was doing wrong :( this piece of PHP code was not mine originally, and that's why i was having trouble understanding it..

The thing is, i was trying to send data with 'Content-Type: application/x-www-form-urlencoded' but was trying to send an object generated from a JSON String..

And after reading some of your API examples, you send the JSON String directly with 'Content-Type: application/json' and i just tried that, and IT WORKED perfectly of course... it was a matter of confusion from my part.. sorry.

Thanks you so much for trying to help :)

I'll keep in touch if something else come up.


Bst regards,
Pedro Carvalho

Pedro Carvalho

unread,
Dec 12, 2016, 4:58:29 AM12/12/16
to floreysoft
Hello,

just to give a closure to this issue, i found out what i was doing wrong.

I was trying to send data with 'Content-Type: application/x-www-form-urlencoded' but was trying to send an object generated from a JSON String..

And after reading some of your API examples, you send the JSON String directly with 'Content-Type: application/json' and i just tried that, and IT WORKED perfectly of course... it was a matter of confusion from my part.. sorry.

Thanks you so much for trying to help :)
Reply all
Reply to author
Forward
0 new messages