I am a newbie in coding-some experience in python. Our company(Finance) is using software called Xceptor to process the data and adding the function of including the table in the message body with HTML. But one thing that really bothers me is when there's no information in the Listfield, I want to output text only and doesn't show the table. Display header and content when there is something, including a sentence indicating how many. Is it possible? Here is the sample script.It works well in W3 school editor but script part doesn't work in that platform I am using.Does any one have any suggestion for that? Thank you for your help and have a good one.
<table border="1" id="MyTable">
<p id="count"></p>
<tr>
<th>Record Type</th>
<th>Trade Date</th>
<th>Account</th>
<th>Transaction</th>
<th>Traded Asset</th>
<th>Proceed CCY</th>
<th>Settlement Date</th>
<th>Quantity Traded</th>
<th>SHORTNAME</th>
<th>ACCT_ID</th>
</tr>
{[List Field]}
</table>
<script>
var rowCount = document.getElementById("myTable").rows.length;
if(rowCount <= 1 ) {
document.getElementById("myTable").style.display = "none";
} else{
document.getElementById("count").innerHTML = "There are "+(rowCount-1) +"row(s)";}
</script>
Identity strings are case sensitive. You misspelled it in your version. With document.getElementById("MyTable"); it will work:
const tbl = document.getElementById("MyTable"), rows=tbl.rows.length-1
if(rows)
document.getElementById("count").innerHTML = `There ${rows==1?"is one row":`are ${rows} rows`}`;
else tbl.style.display="none";
<p id="count"></p>
<table border="1" id="MyTable">
<tr>
<th>Record Type</th>
<th>Trade Date</th>
<th>Account</th>
<th>Transaction</th>
<th>Traded Asset</th>
<th>Proceed CCY</th>
<th>Settlement Date</th>
<th>Quantity Traded</th>
<th>SHORTNAME</th>
<th>ACCT_ID</th>
</tr>
<tr>
<td>Type</td>
<td>Trade Date</td>
<td>Account</td>
<td>Transaction</td>
<td>Traded Asset</td>
<td>Proceed CCY</td>
<td>Settlement Date</td>
<td>Quantity Traded</td>
<td>SHORTNAME</td>
<td>ACCT_ID</td>
</tr>
{[List Field]}
</table>
HTML is a markup language and not programming language so you cannot use if statements in HTML. You will need to do it with help of Javascript.