2

I have the following code on a field in a Peoplesoft BI Publisher RTF template where it is masking the last 4 digits of the Bank Account number.

<?xdofx:lpad('',length(Bank_Account__)-4,'*')?> 
<?xdoxslt:rtrim(xdoxslt:right(Bank_Account__,4))?>

The problem is that sometimes the total Bank Account number length is less than 4 digits and when this happens it causes an negative array error on the lpad function to occur.

Can I wrap some kind of conditional IF statement around this where it will check the length of the bank account number and if it is longer than 5 digits than mask the last 4 digits, else (for Bank Account numbers less than 5 digits) just mask the last 2 digits. What would this look like?

Thanks in advance!

EDIT:

I should add that the existing code above is already wrapped in the following IF statement:

<?if@inlines:Bank_Account__!=''?>

So the entire statement is:

<?if@inlines:Bank_Account__!=''?>
    <?xdofx:lpad('',length(Bank_Account__)-4,'*')?> 
    <?xdoxslt:rtrim(xdoxslt:right(Bank_Account__,4))?>
<?end if?>

I would just like to add in the conditional logic to check the bank account length and subsequently perform either of the above masking.

EDIT 2: Here is my setup with your suggested changes, but I don't think I have the logic nested right, and the syntax may also be an issue.

enter image description here

Edit 3:

Here is the modified code, and the resulting error message:

enter image description here

enter image description here

Nick
  • 268
  • 8
  • 33
  • Usually it's the last four of the number that are shown, not masked. Any time I see an account number anywhere, it always shows the last four digits. – EdHayes3 Jan 30 '19 at 15:31
  • Yes thats what I mean't, the problem is some of the account numbers are less than 4 digits. – Nick Jan 30 '19 at 17:45

1 Answers1

2

The if statements can be nested, but since BIP does not have an else clause, the second if conditions has to check for the negative case.

Maybe this might work:

<?if@inlines:Bank_Account__!=''?>
    <?if@inlines:string-length(Bank_Account__)>4?>
        <?xdofx:lpad('',length(Bank_Account__)-4,'*')?><?xdoxslt:rtrim(xdoxslt:right(Bank_Account__,4))?>
    <?end if?>
    <?if@inlines:string-length(Bank_Account__)<=4?>
        <?xdofx:lpad('','2','*')?><?xdoxslt:rtrim(xdoxslt:right(Bank_Account__,string-length(Bank_Account__)-2))?>
    <?end if?>
<?end if?>

Update: Here is a screenshot of what I got:

enter image description here

Here is the xml snippet I used.

<?xml version="1.0"?>
<root>
  <record>
    <Bank_Account__>123456</Bank_Account__>
  </record>
    <record>
    <Bank_Account__>12345</Bank_Account__>
  </record>
    <record>
    <Bank_Account__>1234</Bank_Account__>
  </record>
    <record>
    <Bank_Account__>123</Bank_Account__>
  </record>
    <record>
    <Bank_Account__>12</Bank_Account__>
  </record>
</root>

Download working files from here

There are some more functions available for other ways to implement this requirement.

Ranjith R
  • 1,571
  • 1
  • 11
  • 11
  • Are you missing a closing IF `` above ? I set this up 2 If statements, in the header if contains `` and then I am putting the nested If logic on the field next to it. Is that correct, or can the entire If (for the length greater than 4 case) be put into the main If field? I'll edit the post above (Edit 2) for clarity... – Nick Jan 30 '19 at 17:42
  • I have formatted the earlier answer. There is one outer If.endif, and two more if.endifs inside that. – Ranjith R Jan 30 '19 at 22:17
  • Thanks - I modified the code as you suggested however I am getting the negative error error when I try to preview the file. Please see Edit 3 above for the changes I made in the Field Browser and the resulting error message. In this case the Account number field is only 3 digits long so it should be masking just the first 2 digits. – Nick Jan 30 '19 at 22:33
  • Updated answer again. string-length has to be used instead of length, inside if conditions. Download my files from here : https://transfer.sh/jxd8z/inp.zip – Ranjith R Jan 30 '19 at 23:13
  • @RanjithR regarding your comment about BIP not supporting else clauses: You can use a `'true''false'` structure or use `` and `` – Based Jan 31 '19 at 13:39
  • @RanjithR this works as expected! Thanks! Trying to learn more about coding with BI Publisher templates. I see that both SQL syntax and XSL syntax can be used in the RTF template. If there are any good resources you would recommend, feel free to provide a link. – Nick Jan 31 '19 at 16:30