Salesforce

Display Conditional or Repeatable Content Within Integrations

« Go Back
Information
Display Conditional or Repeatable Content Within Integrations
using-af-repeat-and-af-if-to-display-conditional-or-repeatable-content-within-integrations
Article Details

Table of Contents

Introduction

The functions of  @af:if and @af:repeat can be used to display conditional or repeatable content within Integrations, especially for email and printable (PDF) integrations, allowing users to bespoke the output to be tailored for the user receiving them.  However they can be costly in terms of resource required to build and test, and changes in a form design will not be reflected in a bespoke email/PDF without corresponding changes to the integration.  An alternative is to use a simple email and access the content through Dash/MyRequests in Self.


Using @af:if and af:repeat

Within the Integrations Manager you have access to the content editor for the integration, where you can use all the edit features and token assistant to create custom content.

wysiwyg editor

 

When using @af:if and @af:repeat the syntax (including spacing) is crucial and therefore we advise that you use Notepad++ to create your statement and copy this into the Source Code of the integration in Integrations Manager. This will avoid unnecessary tags being added into your af:if/af:repeat statement and retain the desired format for output (for example, in a printable/email integration).  To access the source code option, click Tools from the WYSIWYG editor menu.  Using af:if can enable custom output based on a range of field entries made to a form, especially in regard to check boxes and select fields.

.

tools

 

Syntax for @af:if

@af:if can be used with forms and subforms

  • Normal form field

@af:if({text1} = 'Text to compare')
if condition is true then display this message.

@endaf:if

  • Using Subform field

@af:if({subform/text1} = 'Text to compare')
if subform text element has same value then display this message. 
@endaf:if

 

Syntax for @af:repeat

Important:  If there is a space after repeat in the syntax of  @af:repeat({subform1}) this causes the parser to get the wrong count for the subform and cause the printable to have an invalid amount of entries for the subform, resulting in many duplicates, removing the space will allow the token to be evaluated correctly and the af repeat to work as intended.

@af:repeat works with subforms  (repeatable or non-repeatable)

@af:repeat({subform1})
Text will come here.
you can use subform elements here.
{subform1/text1}
{subform1/text2}
@endaf:repeat

Using af:repeat in a table

where subform called Orders - and repeatable fields are item/price/quantity

<table> 
 <tbody> 
  <tr>
   <th>i</th>
   <th>p</th>
   <th>q</th>
  </tr> 

  <![CDATA[ @af:repeat({Orders}) ]]> 
   <tr> 
    <td>{Orders/item}</td> 
    <td>{Orders/price}</td> 
    <td>{Orders/quantity}</td> 
   </tr> 

  <![CDATA[ @endaf:repeat ]]>
 </tbody> 
</table>
 

Using af:if in a table

See example of af:repeat above but where that has af:repeat, replace with af:if. 

Note: Do not include a # symbol before the af:repeat or af:if value; use the example above (you will see that it is not '#Orders'. This causes issues.

NoteIf you are trying to conditionally show a specific row or cell, they will still show but without any content, so this may not produce the desired result.

Using Tokens in Output (Printable/email)

For V2 integrations you will need to use a hash in token names to render html e.g {#textarea1}.   A subform only renders as html where referenced directly as a token eg if in a printable you had {subform1}   it would not display the html unless used as {#subform}. However when being used in af:repeat you do not need to use the #

Using af:if with Upload controls (to pass to webservice)

 @af:if({upload_demo_cnt}>='1')    
{
\"uri\":\"sandbox-files://irrelevant\"    ,
\"isEncoded\":true    ,
\"type\":\"text/plain\"    ,
\"name\":\"@af:base64({upload_demo:1}!)\"    ,
\"content\":\"@af:base64({upload_demo:1})\"
}  
@endaf:if  

@af:if({upload_demo_cnt}>='2')    ,
{
\"uri\":\"sandbox-files://irrelevant\"    ,
\"isEncoded\":true    ,
\"type\":\"text/plain\"    ,
\"name\":\"@af:base64({upload_demo:2}!)\"    ,
\"content\":\"@af:base64({upload_demo:2})\"
}  
@endaf:if  

@af:if({upload_demo_cnt}>='3')    ,
{
\"uri\":\"sandbox-files://irrelevant\"    ,
\"isEncoded\":true    ,
\"type\":\"text/plain\"    ,
\"name\":\"@af:base64({upload_demo:3}!)\"    ,
\"content\":\"@af:base64({upload_demo:3})\"
}  
@endaf:if

Using an Upload Field within a Subform

  • Subform (non repeatable) / upload field (mandatory / single item  - works
  • Subform (non repeatable) / upload field (mandatory / multiple items) - works
  • Subform (non repeatable) / upload field (optional / single/multiple items) - if formatting into a table then you need to determine which of the upload has been submitted - as the upload name is combined into one string, you'll need to use a method to split this out into the each upload field name - this will allow you to use the @af:if to determine whether the fieldname is populated and if so display/print this row/image (as below).

repeatable values in subforms displayed

  • Subform (repeatable) - When this repeats for each row its not possible to use the logic to pick up the specific row - this is unsupported.

top of page


Limitations

  • This functionality is not supported by Payment Integrations
  • You can use following operators in '@af:if' condition 
    =, ==, <=, <, >=, >, !=, !(= equates to equals, == is comparable to === ie equal value and equal type, !=  is not equals)
  • Note; <> will not work please use !=
  • The AND an OR syntax doesn't work with AF Repeat or AF IF using V1 integrations, but this does work using V2 integrations.
  • For complicated calculations you need to do these in the form first and then base your AF off of that.  For example you would have a field with this in it in the form

    if(({fieldA} = 'false') && ({fieldB} = 'false') && ({fieldC} = 'true')),'show','hide').

    Then on the AF:IF you would use;

    @af:if({newfield}='show')
    some text here
    @endaf:if


    Please ensure there are NO spaces after af:if or af:repeat tags and the opening bracket

  • Spaces should be used inside the CDATA square brackets
    For example:
    ![CDATA[ @af:repeat({firemapcustomertable}) ]]

    Please ensure you retain the spaces around the inner text as this is essential in Integrations V2.
  • Note the syntax is very important and when comparing a field to a statement it is necessary to ensure the comparison text is encased in open quotations "  not single quotes/apostrophes ' (note: two apostrophes '' does not equate to an open quote "  - if your integration is not behaving as you expect - please remove and retype the quotation marks (note quotes copied from word will be incorrect and will cause issues - hence advising using notepad)

Additional Notes

  • If you receive the error 'End tag afend:repeat]] does not match tag af:repeat at line 00, character 0' or similar, it is because you have not correctly spaced the CDATA tag in a V2 integration. Please ensure you retain the spaces around the inner text as this is essential in Integrations V2.
  • Please ensure there are no spaces between the tags af:if and af:repeat and brackets
 

top of page


Examples

Following are some examples to use @af:repeat and @af:if.

(Email) Integration Examples :

Example 1 : Two If blocks

Two If Blocks
Text1 value :{text1}
Number value : {number1}

 

@af:if({text1} = 'text could be long')

  Display it when text1 is equal to the string : {text1}

 this search is case in-sensitive

@endaf:if

Second if statement in same integration 

@af:if({number1} <= '312'

     display number value: {number1}

@endaf:if

 

Result of Example 1 :

Result : Two if Blocks

Text1 value :text could be long

Number value : 12

Display it when text1 is equal to the string : text could be long

this search is case in-sensitive

Second if statement in same integration

  display number value: 12

 

Example 2 : Nested Ifs

Nested Ifs

Example 2 : Nested Ifs

Text1 value :{text1}

Number1 value : {number1}

Number2 value : {number2}

@af:if({text1} ='text to compare')

   display this text, if first if condition is met.

@af:if({number1} = '100')

display this if number1 has 100 in it.  number1 value : {number1}

@endaf:if

@af:if({number2} = '121') display thisif number2 has 121 in it. text 3 value : {number2} @endaf:if

@af:if({number2} < '121') display thisif number2 is less than 121. text 3 value : {number2} @endaf:if

@af:if({number2} != '121') Display thisif number2 is not equal to 121. text 3 value : {number2} @endaf:if

any string can come here. 

this following end af:if is closing of initial af:if.  where text1 equal to ‘text to compare’

@endaf:if

 

Result of Example 2 :

Result : Nested Ifs

Text1 value :Text to Compare

Number1 value : 100

Number2 value : 120

display this text, if first if condition is met.

display this if number1 has 100 in it.  number1 value : 100

display thisif number 2 is less than 121. number2 value : 120

Display thisif number2 is not equal to 121. number2 value : 120

any string can come here.

this following end af:if is closing of initial af:if.  where text1 value : 'Text to Compare' equal to 'text to compare'

 

Example 3 af:repeat with outer af:if

af:repeat with outer af:if

@af:if({number1}< '121')

Display below text and repeat subform, if text is less than 121

  @af:repeat({subform1/text1})

   this is text inside subform: {subform1/text1}

   You can use number1 here . number1 value : {number1}

  @endaf:repeat

value of number1 can be displayed here : {number1}

@endaf:if

 

Result of Example 3: 

Result : af:repeat with outer af:if

Display below text and repeat subform, if text is less than 121

this is text inside subform: sf42

You can use number1 here . number1 value : 45

this is text inside subform: 356

You can use number1 here . number1 value :45

value of number1 can be displayed here : 45

  

Example 4 af:repeat and inside af:if

 af:repeat and inside af:if

@af:repeat({subform1})

 text 1 value        - {text1} - 

 textarea1 value  - {textarea1}  -

 

 @af:if({subform1/number1} <= '121'

  Display this text, if subform1/number1 is less than equal to 121

  subform/number1 value : {subform1/number1}

 @endaf:if

@af:if({number1} <= '121'this is inside first repeat and if condition for number1 

@endaf:if

Text area value : {textarea1}

@endaf:repeat

 

Result of Example 4:

Result : af:repeat and inside af:if

text 1 value        - 34 

textarea1 value  - sfwefwe -

Display this text, if subform1/number1 is less than equal to 121.

subform/number1 value : 34

this is inside first repeat and if condition for number1

Text area value : sfwefwe

 

top of page

 

 

Further useful reading:

 
           
     
     

    top of page

     
     
     
     


     

    Powered by