Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Can you use Qualifiers when using data binding and a schema

Avatar

Level 1

I am very new to the ALC designer and have only worked in a limited range to create fields and map those fields directly to an element in the schema.

My xml instance looks like the below

<person>

      <PersonAddress>

             <AddressType>Home</AddressType>

             <Address>123 Street, Sandiego, California</Address>

      </PersonAddress>

      <PersonAddress>

             <AddressType>Mailing</AddressType>

             <Address>123 Street, Sandiego, California</Address>

      </PersonAddress>

      <PersonAddress>

             <AddressType>Employer</AddressType>

             <Address>123 Street, Sandiego, California</Address>

      </PersonAddress>

<person>

The Address information does not need to come in the same order as above and in some instances one of the addres might not be there.

I have an existing PDF which has been imported as an artwork. It has 3 checkboxes, EmployerAddress Checkbox, Mailing Addres Checkbox and Home Address Checkbox

I would like the checkboxes to be turned on if the corresponding Address type is present in the instance. Moreover there is a text area next to each checkboxes for the related addresses. 

What is the easiest way to acheive this without doing an xslt to transform the existing instance into another.

Thanks is advance for your comments/responses.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

So I'm guessing it is valid to have a PersonAddress element without an AddressType element.  The predicate is going to go though your dataset and evaluate the expression for each PersonAddress.

So if AddressType is optional you will need to guard against this error, something like;

$.PersonAddress.[if (Exists(AddressType)) then AddressType=="Home" endif].Address

Also is the AddressType value Mail or Mailing? The error message does not match the original XML.

Regards

Bruce

View solution in original post

4 Replies

Avatar

Level 10

Hi,

The text fields could be bound to an Address element with a predicate expression, so for the home address use;

$.PersonAddress.[AddressType=="Home"].Address

I don't think you will be able to bind the checkboxes, but you could populate them in the calculate event with this FormCalc;

HasValue(Home)

Where "Home" is the name of the text field that has the binding expression above.

Bruce

Avatar

Level 1

Thank you Bruce, With your help I was able to get it working for the Home Check box. However when I replicated the same for the Mail and Employer by changing the qualifier only it is giving me the following error

Generating PDF Document...

PDF generated successfully.

Generating PDF Document...

Script failed (language is formcalc; context is xfa[0].datasets[0].data[0].PersonAddress[0].)

script=AddressType=="Mail"

   Error: accessor ' AddressType' is unknown.

Malformed SOM expression:

$.PersonAddress.[AddressType=="Mail"].Address

   Error: accessor 'AddressType ' is unknown.

End of processing: Failure

Moreover when I remove the mail and employer reated it works for home. It seems like it does not like me using the same element for more than one fields.

Please assist.

Avatar

Correct answer by
Level 10

Hi,

So I'm guessing it is valid to have a PersonAddress element without an AddressType element.  The predicate is going to go though your dataset and evaluate the expression for each PersonAddress.

So if AddressType is optional you will need to guard against this error, something like;

$.PersonAddress.[if (Exists(AddressType)) then AddressType=="Home" endif].Address

Also is the AddressType value Mail or Mailing? The error message does not match the original XML.

Regards

Bruce

Avatar

Level 1

Thank you Bruce, you were right with the value "Mailing". I corrected that and it seems to work. I have also put in the If statement you suggested since the field is optional.

Thanks once again. Malavika