• Post category:BI Publisher
  • Post comments:0 Comments
  • Post last modified:August 7, 2020
  • Reading time:5 mins read
You are currently viewing How to use IF IF-ELSE OR AND conditions in RTF template BI Publisher
How to use IF IF-ELSE OR AND conditions in RTF template BI Publisher

In this article we will look into different ways of writing the IF condition in RTF template to achieve complex requirements.

Every BIP or HCM Extract will have a template tagged to them to get the output in different formats.. RTF is the most common template to get the output in PDF/HTML/Excel.

If there is a requirement to write conditional logic in RTF template, then IF condition can be used in such cases. Mostly in case of letters (Offer Letter/Appraisal Letter) to conditionally skip/display some paragraphs and also in regular templates when there are condition based calculations.

Table of Contents

Method 1:

Use If statement directly in the template as Text or form field

<?if:FLAG_1=’Y’?> Yes <?end if?>

Method 2:

Use If else statements using xdofx command

<?xdofx:if SALARY > 10000 then 'Salary More than 10K' else 'Salary less than 10K' end if?> 

Method 3:

Nested If Sample using xdofx

<?xdofx:if ../../../PAYMENT_DETAILS/PAYER_METHOD/PAYMENT_METHOD_NAME = 'RRSP Cheque' then
(
if instr(../../../PAYMENT_DETAILS/THIRD_PARTY_DETAILS/THIRD_PARTY_BREAKDOWN/GLB_ARCH_TPP_PAYMENTS/GLB_PAY_ARCH_TPP_ADDRESS/TPP_PAYEE_NAME,'-',1,1) > 0 then
substr(../../../PAYMENT_DETAILS/THIRD_PARTY_DETAILS/THIRD_PARTY_BREAKDOWN/GLB_ARCH_TPP_PAYMENTS/GLB_PAY_ARCH_TPP_ADDRESS/TPP_PAYEE_NAME,1,instr(../../../PAYMENT_DETAILS/THIRD_PARTY_DETAILS/THIRD_PARTY_BREAKDOWN/GLB_ARCH_TPP_PAYMENTS/GLB_PAY_ARCH_TPP_ADDRESS/TPP_PAYEE_NAME,'-',1,1)-1)
else
../../../PAYMENT_DETAILS/THIRD_PARTY_DETAILS/THIRD_PARTY_BREAKDOWN/GLB_ARCH_TPP_PAYMENTS/GLB_PAY_ARCH_TPP_ADDRESS/TPP_PAYEE_NAME
)
else
../../GLB_PAY_ARCH_EE_INFO/DISPLAY_NAME
?>

Method 4:

If else condition using xdoxslt

<?xdoxslt:ifelse(condition,true,false)?>

Sample to display different field value based on a field value

<?xdoxslt:ifelse(BASE_NAME = 'HOURS',VALUE,CAL_VALUE)?>

Method 5:

Use choose statement if there are multiple conditions

<?choose:?>
<?when: COMPANY=111?>Legal Entity 1<?end when?>
<?when: COMPANY=222?>Legal Entity 2<?end when?>
<?when: COMPANY=333?>Legal Entity 3<?end when?>
<?otherwise?>Legal Entity 4<?end otherwise?>
<?end choose?>

Using OR and AND conditions in the IF statement:

We have to be very careful with the syntax of the statement that we write when we use the OR and AND commands as they don’t work if we don’t follow the proper syntax

Syntax:

<?if:XMLfield=value1 or XMLfield=value2?> display Calue <?end if?>

Example:

<?if:(sum(VALUE)=0 or sum(AMOUNT)=0)?>0<?end if?>

We need to enclose the total condition in braces ( and ).

The operators or & and should be in lower case only else they won’t work properly.

If there are multiple conditions based on which some text needs to be shown it can be written as below using and & or conditions.

<?if:((MEMBER='N' and SALARY_BASIS_CODE='HOURLY') and (ASG_CAT='Full-time' or ASG_CAT='Part-time') and (CITY='Las Vegas' or CITY ='Laughlin'))?>

Note: Make sure you use braces for the entire condition & ensure that or & and are used in lower case to make the condition work perfectly.

Hope this is useful. You can use any of the above methods depending on your requirement.