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
IZavalunIZavalun 

PLEASE HELP!!!!!!!!!!!!!

Hello - Please help to fix my syntax problem here, I need to get the contact in function cm(contact)...
Please see in red:
==============================================
 
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
var fn = "cm(this)";
function do_code()
{
//////////////////////////////////////
var cust_name =  '{!Account.Name}';
var qrdr5 = sforce.connection.query("Select c.Id from Account c  where c.Name= '" + cust_name + "'");
var records = qrdr5.getArray("records");
for (var x = 0; x < records.length; x++)
{
tt5 = records[x];
var ttt = tt5.get("Id");
}
/////////////////////////////////////
var qrdr2 = sforce.connection.query("Select Name from Contact c  where AccountId= '" + ttt + "'order by createdDate");
var records = qrdr2.getArray("records");
document.write("<b><u>Please Select Customer Contact:</u></b><BR><BR>");
document.write("<HR>");
for (var y = 0; y < records.length; y++)
{
tt2 = records[y];
var t=tt2.get("Name");
document.write("<BR>");
output = "<input id=btn1 type=button name=btn1 onclick=cm(obj); value='" + t + "'>";
document.write(output);
document.write("<BR>");
}
document.write("<BR>");
document.write("<HR>");
}
////////////////////////////////////
function cm(contact) {
  alert(contact);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Customer Contacts...</title>
</head>
<body onLoad="do_code();">
</body>
</html>
mikefmikef
You should be able to just change this line:

output = "<input id=btn1 type=button name=btn1 onclick=cm(obj); value='" + t + "'>";

To

output = "<input id=btn1 type=button name=btn1 onclick=cm('" + t + '"); value='" + t + "'>";

Or
var con = t + " " + tt2.[fieldNames]

output = "<input id=btn1 type=button name=btn1 onclick=cm('" + con + '"); value='" + t + "'>";


hope this helps




IZavalunIZavalun

Unfortunatelly it didn't work...

I am still waiting for some sugestions.

SteveBowerSteveBower
So, a few things.

1. Screaming "PLEASE HELP!!!!!" in your subject line makes me think you've got an urgent problem instead of some lame javascript issue.

If you actually *have* an urgent problem then I respect you for the urgency.  But, when you've just got some sample code that you can't get to work and you're screaming for help, it makes me think you're just clueless.

2. Second pointing out that you're still waiting for suggestions on a public discussion board after you've already received one in just two hours is also kind of goofy.  The world does not flock to help you solve your problems.  You might say thanks to the guy who essentially gave you the right answer.

3. Provide some more data if the first suggestion didn't help.  Provide data as to *why* the suggestion didn't help?  Did you look at the generated Javascript?  What does it look like?  What behavior *do* you get?  Did you Google "onclick Javascript" to see what others do?

Best of luck.  Steve.

p.s. Lastly, you should combine your two queries into one for speed.  Consider using error handling.

SteveBowerSteveBower
Man, I'm getting cynical these days...  :-)   I apologize for the lecture, I know where my delete key is.  :-)  -S
sfdcfoxsfdcfox
You mixed the Beta toolkit with the Production syntax. Bad Mojo.
 
Change https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js to "/soap/ajax/10.0/connection.js". Then check your syntax. If you've still got errors, come back and we can help ya.
 
And, I suppose I could ask you not to scream unless it's a life or death emergency ;-).
 
~ sfdcfox ~
sfdcfoxsfdcfox
Oh, and technically, don't use...
 
getArray("records")
 
...use...
 
QueryResultIteraor = new sforce.QueryResultIterator(QueryResult)
 
...syntax instead. That way, you can do a loop such as...
 
while(QueryResultIterator.hasNext())
{ ResultItem = QueryResultIterator.next();
  // do something with the result item.
}
 
The cool thing about that is you get to auto-queryMore at no cost to you, so you can accurately process all of the records. Also handles null occurances (ie. result set is empty). You can even nest result iterators inside inner loops as necessary for sub-queries (ie. 'select id,(select id from contacts) from account').
 
~ sfdcfox ~
IZavalunIZavalun
Very good points!!! Thanks I got it working.