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
KringoKringo 

Inline S~Control ~and I'm stuck

I'm a admin with a couple years under my belt trying to learn some of this code stuff. I've been working on this piece for a few hours (i'm embarressed to say how many) and I'm stuck. I've posted the code. What I'm trying to do is use an inline scontrol to display account site info in a record that is at the detail end of a relationship with account.
Code:
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Account</title>

<!-- Include the SalesForce style sheets -->
<link href="/sCSS/Theme2/en/common.css
media="handheld,print,projection,screen,tty,tv" rel="stylesheet"
type="text/css" />
<link href="/sCSS/10.0/Theme2/allCustom.css"
media+"handheld,print,projection,screen,tty,tv" rel="stylesheet"
type="text/css" />

<-- get the AJAX toolkit -->
<script src="/soap/ajax/10.0/connection.js"></script>
<script>

var AccountId= "{!Service__c.Account__c}";

function failure(error) {
document.body.innerHTML += "Error retrieving Account info";
document.body.innerHTML += "<br>API Error: " + error;
}

function initPage() {

try{
//alert(AccountId);
var result = sforce.connection.retrieve("Account_Site, Owner","Account" [AccountId],
{onSuccess: render, onFailure: failure});

} catch (e) {
document.body.innerHTML += "Error retrieving Account info";
document.body.innerHTML += "<br>Fault code: " + e.faultcode;
document.body.innerHTML += "<br>Fault string: " + e.faultstring;

}

}

function render(result) {

try {

var record = result [0];

var output = "<div class='bPageBlock secondaryPalette' id='ep'>";

output += "<div class='pbHeader'>";
output += "<div class='pbBody'>";
output += "<div class='pbSubsection' style='display: block;'>"


output += "<tr>";
output += "<td class='labelCol'>Account</td>"
output += "<td class='dataCol col02'><a target='_top' href=/"
+ AccountId + ">" + record.Account_Name + "</a></td>"
<td class='labelCol empty'> </td>
<td class='dataCol empty'> </td>";
output += "</tr>";
output += "<tr>";
output += "<td class='labelCol'>Account Site </td>";
output += "td class='dataCol'>" + Account.Site + "</td>";
output += "</tr></table>";
output += "</div></div></div><div class='pbFooter
secondaryPalette'><div class='bg'/></div></div>';



document.body.innerHTML += output;

} catch (e) {
document.body.innerHTML += "Error retrieving candidate information";
document.body.innerHTML += "<br>Fault code: " + e.faultcode;
document.body.innerHTML += "<br>Fault string: " + e.faultstring;
}
}
</script>
</head>
<body class="custom customTab79 detailPage" onload="initPage();">
<div id="mainbody"></div>
</body>
</html>

 

any nudge in the right direction would be much appreciated
BritishBoyinDCBritishBoyinDC
I think the field you want is just called 'Site', unless you have created a new field?

If you do an alert on record.Site, is it available?

This part below also looks wrong to me - you never actually retrieved the Account name in the original call, so you can't display it  - and I think it would be record.Name if you did. And in in the second section, you say Account.Site - that should be record.Site I think.

Code:
<a target='_top' href=/"
+ AccountId + ">" + record.Account_Name + "</a></td>"

....

output += "<td class='labelCol'>Account Site </td>";
output += "td class='dataCol'>" + Account.Site + "</td>";

 

CaptainObviousCaptainObvious
I haven't tested this, but it may help (fixed a few syntax errors):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title>Account</title>

<!-- Include the SalesForce style sheets -->
<link href="/sCSS/Theme2/en/common.css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" type="text/css" />
<link href="/sCSS/10.0/Theme2/allCustom.css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet" type="text/css" />

<!-- get the AJAX toolkit -->

<script src="/soap/ajax/10.0/connection.js"></script>
<script language="javascript">

var AccountId= "{!Service__c.Account__c}";

function failure(error) {
 document.body.innerHTML += "Error retrieving Account info";
 document.body.innerHTML += "<br>API Error: " + error;
}

function initPage() {

 try{
  //alert(AccountId);
  
  var accountId = new Array();
  accountId[0] = AccountId;   
  var result = sforce.connection.retrieve("Name, Site, Owner","Account", [accountId[0]],
      {onSuccess: render, onFailure: failure});
  } catch (e) {
   document.body.innerHTML += "Error retrieving Account info";
   document.body.innerHTML += "<br>Fault code: " + e.faultcode;
   document.body.innerHTML += "<br>Fault string: " + e.faultstring;
 }

}

function render(result) {

 try {

 var record = result[0];
 var output = "<div class=\"bPageBlock secondaryPalette\" id=\"ep\">";
 
 output += "<div class=\"pbHeader\">";
 output += "<div class=\"pbBody\">";
 output += "<div class=\"pbSubsection\" style=\"display: block;\">"
 
 output += "<table cellpadding=1 cellspacing=1 border=0>";
 
 output += "<tr>";
 output += "<td class=\"labelCol\">Account</td>";
 output += "<td class=\"dataCol col02\"> <a href=\"https://na2.salesforce.com/" + AccountId + "\"target=\"_top\">" + record.Name + "</a>";
 output += "</td>";
 output += "</tr>";
 
 output += "<tr>";
 output += "<td class=\"labelCol\"> Account Site </td>";
 output += "<td class=\"dataCol\">" + record.Site + "</td>";
 output += "</tr>";
 
 output += "</table>";
 
 output += "</div></div></div><div class=\"pbFooter secondaryPalette\"><div class=\"bg\"/></div></div>";
 
 document.body.innerHTML += output;
 
 } catch (e) {
  document.body.innerHTML += "Error retrieving candidate information";
  document.body.innerHTML += "<br>Fault code: " + e.faultcode;
  document.body.innerHTML += "<br>Fault string: " + e.faultstring;
 }
}

</script>
</head>
<body class="custom customTab79 detailPage" onload="initPage();">
<div id="mainbody"></div>
</body>
</html>

As BritishBoyinDC mentioned, you should probably go with record.Name and record.Site. Also, you may have to adjust the hyperlink "https://na2.salesforce.com" to match your instance.
KringoKringo
Awesome! I've got it working.

In addition to the multitudes of syntax errors I wasn't calling AccountId into the global variable.

Thank you both very much.