You need to sign in to do that
Don't have an account?

Ajax toolkit Listview problem
Using the Ajax toolkit I've created an HTML S-Control that uses the API to retreive certain Contacts. I have also modified the code to retreive the parent Account Name (lifted from toolkit samples).
My problem is that the table renders and does not fail but I can't find the right field name to display the Contact's Account.
Any ideas? I'm totally new to S-Controls and Java.
Here's my query:
Here's the full code:
Here's the results with the Account column blank:
My problem is that the table renders and does not fail but I can't find the right field name to display the Contact's Account.
Any ideas? I'm totally new to S-Controls and Java.
Here's my query:
var result = sforce.connection.query("SELECT c.Phone, c.title, c.firstname, " +
"c.lastname, c.email, a.Id, a.name, a.industry, c.accountId " +
"FROM Contact c, c.account a limit 10");
and here's the line where I try to display results:
sb.append("</td><td> ").append(editLink(record, "a.Name"));
I've tried many names, but nothing displays the Account NameHere's the full code:
Code:
<html> <!-- Generated by AJAX tools Date : Thu Dec 13 2007 10:48:29 GMT-0500 (Eastern Standard Time) Template : listview.html by manoj@cheenath.com SControl : DummyContact --> <html> <head><title>listview</title> <link rel="shortcut icon" href="/favicon.ico"/> <script src="/soap/ajax/8.0/connection.js"></script> <script src="/js/dojo/0.3.1/dojo.js"></script> <title>DummyContact</title> <style> table { font-family: Lucida Grande, Verdana; font-size: 0.8em; width: 100%; border: 1px solid #ccc; cursor: default; } * html div.tableContainer { /* IE only hack */ width: 95%; border: 1px solid #ccc; height: 285px; overflow-x: hidden; overflow-y: auto; } table td, table th { border-right: 1px solid #999; padding: 2px; font-weight: normal; } table thead td, table thead th { background: #94BEFF; } * html div.tableContainer table thead tr td, * html div.tableContainer table thead tr th { /* IE Only hacks */ position: relative; top: expression( dojo.html.getFirstAncestorByTag(this, 'table').parentNode.scrollTop-2); } html>body tbody.scrollContent { height: 262px; overflow-x: hidden; overflow-y: auto; } tbody.scrollContent td, tbody.scrollContent tr td { background: #FFF; padding: 2px; } tbody.scrollContent tr.alternateRow td { background: #e3edfa; padding: 2px; } tbody.scrollContent tr.selected td { background: yellow; padding: 2px; } tbody.scrollContent tr:hover td { background: #a6c2e7; padding: 2px; } tbody.scrollContent tr.selected:hover td { background: #ff3; padding: 2px; } </style> <script type="text/javascript"> dojo.require("dojo.widget.SortableTable"); dojo.addOnLoad(displayTable); function displayTable() { //*********** Query *********************************** var result = sforce.connection.query("SELECT c.Phone, c.title, c.firstname, " + "c.lastname, c.email, a.Id, a.name, a.industry, c.accountId " + "FROM Contact c, c.account a limit 10"); //*********** creates Title Header ********************* var sb = new sforce.StringBuffer(); sb.append("<tr>"); sb.append("<td>No</td>"); sb.append("<td>LastName</td>"); sb.append("<td>FirstName</td>"); sb.append("<td>Phone</td>"); sb.append("<td>Title</td>"); sb.append("<td>Account</td>"); sb.append("<td>Email</td>"); sb.append("</tr>"); //**************** fills table with query results ******* while (true) { if (result.size > 0) { for (i = 0; i < result.records.length; i++) { var record = result.records[i]; sb.append("<tr><td>").append(i).append("</td>"); sb.append("</td><td> ").append(editLink(record, "LastName")); sb.append("</td><td> ").append(editLink(record, "FirstName")); sb.append("</td><td> ").append(editLink(record, "Phone")); sb.append("</td><td> ").append(editLink(record, "Title")); sb.append("</td><td> ").append(editLink(record, "a.Name")); sb.append("</td><td> ").append(editLink(record, "Email")); sb.append("</td></tr>"); } } if (result.done == "true") { break; } else { result = sforce.connection.queryMore(result.queryLocator); } } document.getElementById("list-view-table").innerHTML = sb.toString(); } function editLink(record, field) { var value = record[field]; value = value — value : " "; return value; //todo: edit link return "<a href='javascript: editCell(\"" + record.Id + "\",\"" + field + "\",\"" + value + "\")'>" + value + "</a>"; } function editCell(id, field, value) { var newVal = prompt("Enter new text", value); if (newVal === null || newVal === value) { alert("Field not changed"); return; } else { value = newVal; } var record = new sforce.SObject("Account"); record.Id = id; record[field] = value; try { result = sforce.connection.update([record]); if (result[0].getBoolean("success") == false) { alert("update failed"); } else { //initPage(); } } catch (e) { alert("update failed"); //sforce.debug.display(e); } } </script> </head> <body> <div class="tableContainer"> <table dojoType="SortableTable" id="list-view-table" headClass="fixedHeader" tbodyClass="scrollContent" enableMultipleSelect="true" enableAlternateRows="true" rowAlternateClass="alternateRow" cellpadding="0" cellspacing="0" border="0"> </table> </div> </body> </html>
Here's the results with the Account column blank:

Hope this helps you out in your endeavors.
If you meant for me to literally replace
sb.append("</td><td> ").append(editLink(record, "a.Name"));
with
sb.append("</td><td> ").append(editLink(record['Account']['Name']));