function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shan876shan876 

display result from query

hi all
  I have wrote a s control to display something on the page... the only thing is it does not display anything and I know that it should Can someone please help me and tell me where am I going wrong
<html>
<head>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>

<script text="javascript">
var aid='0015000000KxU9SAAV';
function initPage()
//Get the account Number
{
var i,j;
result = sforce.connection.query("Select a.AS400_Account_Number__c, a.Id, " +
"(Select AccountId, CaseNumber From Cases) from Account a where a.Id='0015000000KxU9SAAV'");
records = result.getArray("records");

for (var i=0; i<records.length; i++) {
var record == records[i];
j ==(record.AS400_Account_Number__c);
}

};

/*****************************************************************************/

</script>
</head>
<body onload="initPage();">
</body>
</html>
Thanks
Zishan
aezellaezell
First, there's no code here to actually display anything. I see that you are stuffing the javascript variable "j" with values, but it looks like it will just be overwritten everytime through the loop. Then, you don't do anything with that variable to actually display the values.
Greg HGreg H
Try this:Code:
<html>
<head>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>

<script text="javascript">
var aid='0015000000KxU9SAAV'; //account id from merge field (maybe—)
//function initiated after page load
function initPage() {
 var j = ""; //declaration of variable j
 var soql = sforce.connection.query("SELECT AS400_Account_Number__c FROM Account WHERE Id='"+aid+"'"); //soql query statement
 var records = soql.getArray("records"); //put results into array called records

 for (var i=0; i<records.length; i++) { //for each record in array "records"
  j += "Record "+(i+1)+" is "+records[i].AS400_Account_Number__c+"<br>"; //append some text and the AS400_Account_Number__c value
 }
 document.getElementById("results").innerHTML = j; //put contents of variable j on page
};
</script>
</head>
<body onload="initPage();">
<div id="results">Loading...</div>
</body>
</html>

I left out some of your original code because it couldn't figure out what you were trying to do.  Additionally, although the example loops through a records array it will only contain one row because your query statement explicitly looks for an individual Account Id.
 
I hope the comments in the code make sense but let me know if you have any other questions,
-greg