0

I have a json field that is either absent or is set to true. But in my document I want it to show up as "Yes" or "No". I tried the following conditional expression ():

{% conditional-section expr(`my_field` = true) %}Yes{% end-section %}{% conditional-section expr(`my_field`!= true) %}No{% end-section %}

But when I call the Adobe Document Generation API, the PDF I get still has these template tags. For some reason it is not being detected. How can I achieve this?

  • Hi, quick question. Was your code *exactly* as you have it there, all one line? If so, there is a bug currently where you can't do conditions like that all in one line. It's known so should be fixed soon, but if you can confirm, I can help you with a weorkaround. – Raymond Camden May 27 '21 at 21:56
  • Sorry for the (very) late reply. Yes, the code is exact and does look like a bug. – Venkata Vijay Ventrapragada Oct 06 '21 at 05:34

2 Answers2

0

I know I asked a question above in the comment, but I think I can take a stab at answering this now. So right now there is not a way to say "if a value is NOT present or present and equal to yes." There's a few ways you can handle this, but I think the easiest would be to change your data. To be clear, I don't mean change your database or anything, but keep in mind that before you call our API, you can massage the data a bit. So if the absence of my_field means yes, I'd do something like this (JavaScript):

if(!mydata.my_field) {
  mydata.my_field = 'yes';
}

You could then do something like this:

{% conditional-section expr(my_field = "yes") %}
Yes
{% end-section %}
{% conditional-section expr(my_field = "no") %}
No
{% end-section %}

However, this will not be on the same line. As I said, this is a known issue. If you need it as such, again, I'd use the idea of massaging your data first. You could do something like this (again, JavaScript, but could be done in any language):

if(!mydata.my_field) {
  mydata.my_field = 'yes';
}
if(mydata.my_field === 'yes') mydata.my_field_value = 'Yes';
else mydata.my_field_value = 'No';

All I did there was, based on the value of my_field, set another variable. In your Word template you can then simplify even more by just using {{my_field_value}}

With Document Generation being so flexible, you've got multiple different ways of solving a problem.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
0

I have found this works for me:

{{my_field ? "Yes" : "No"}}