I have a site with multiple Webparts. Some Webparts are linking on the same .html file. The HTML file reads data from a list and displays it in a table by using javascript. My problem is that there is displayd only one table, the other (same)Webparts aren't displayd.
How can I solve this problem?
<html>
<head><title>test import list</title></head>
<body>
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(mainFunction, "sp.js");
var typeNumber = "1520";
try {
function mainFunction() {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Projectstatus');
//empty caml cause of some errors with lookup fields
var emptyCamlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(emptyCamlQuery);
clientContext.load(this.collListItem);
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() {
var listItemInfo = '';
var i = 0;
var oListItem = "";
var statusArray = new Array(3);
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
oListItem = listItemEnumerator.get_current();
if (oListItem.get_item('Title').match(typeNumber)) {
statusArray[i] = oListItem.get_item('Status');
i++;
//not nice! but it works, i'll fix it when everything is working fine
if (i > 2) {
break;
}
}
}
var tableOutput = "<table border=" + "'" + "1" + "'" + "><tr><th>Type</th><th>Status</th></tr>" +
"<tr><td>1</td><td>" + chooseColor(statusArray[2]) + "</td></tr>" +
"<tr><td>2</td><td>" + chooseColor(statusArray[1]) + "</td></tr>" +
"<tr><td>3</td><td>" + chooseColor(statusArray[0]) + "</td></tr>" +
"</table>";
document.getElementById("testDiv").innerHTML = tableOutput;
}
function onQueryFailed() {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function chooseColor(color) {
if (color == "Red") {
return "<img src=" + "images/red.png" + ">";
}
if (color == "Yellow") {
return "<img src=" + "images/yellow.png" + ">";
}
if (color == "Green") {
return "<img src=" + "images/green.png" + ">";
}
}
} catch (e) {
alert(e);
}
</script>
//Problem could be here, cause both Webparts using the same id?
<div id="testDiv" />
</body>
</html>