Jump to content
  • 0

Case statement in an HTML block using an external parameter




I have a tablular datapage that I am trying to create a conditional output based on a external parameter being passed to the datapage.  The external parameter [@BU] is driving the selection of which results should be passed.  The resulting html would be passed for each case.  Not sure if this is possible since it is a mixed logic and HTML response.  Or if I should just be looking for a different solution here"

I have added this in my HTML block currently but the CASE logic is not working and currently it is just parsing the html formatted content:



WHEN '[@BU]' = '8' 
THEN <span month_year="[@field:Month_Year*]" sub_type="[@field:Function_Subtype#]">[@field:MPBU_HC]</span>

WHEN '[@BU]' = '6' 
THEN <span month_year="[@field:Month_Year*]" sub_type="[@field:Function_Subtype#]">[@field:MicBU_HC]</span>



Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0


I am afraid that you cannot use SQL in HTML blocks.

SQL code can be only used in Calculated values\fields.

I would recommend using a JS code in order to achieve described behavior.

1. Add the following code into HTML block:

<p id="[@cbRecordIndex#]"></p>

2. Add the following JS into Datapage Footer:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

let el = document.querySelectorAll('td>p');
let par = '[@BU]';

el.forEach(element => {
    if(par=='8') element.innerHTML = '<span month_year="[@field:Month_Year*]" sub_type="[@field:Function_Subtype#]">[@field:MPBU_HC]</span>';
    else if (par=='6') element.innerHTML = '<span month_year="[@field:Month_Year*]" sub_type="[@field:Function_Subtype#]">[@field:MicBU_HC]</span>';
    else element.innerHTML = '0';

Please make sure that you disable HTML editor before inserting the code.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...