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
MattLMattL 

In-Line S-Control Resolution help

I'm working on an S-control that pulls the date of the most recent Opportunity belonging to an Account and displays that. My problem is that when I attempt to format the field to align with the rest of SFDC fields, it works for the resolution I'm operating on, but as soon as that resolution changes it falls out of sync. I've tried using %, em, and px, and nothing seems to understand the resolution change. How does Salesforce do it?

Code below:

Code:
<!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<link href="/dCSS/Theme2/default/common.css" type="text/css"
media="handheld,print,projection,screen,tty,tv"  rel="stylesheet" >
<link href="/dCSS/Theme2/default/custom.css" type="text/css"
media="handheld,print,projection,screen,tty,tv"  rel="stylesheet" >

<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/setup.js"></script>

<script src="/soap/ajax/9.0/connection.js"></script>

<html>
<head>
<script type="text/javascript">
function init()
{
sforce.connection.sessionId = "{!$Api.Session_ID}";
var acctid="{!Account.Id}";
var LatestOpportunity=sforce.connection.query("Select CloseDate from Opportunity Where AccountId='" + acctid + "'");
var LOrecs = LatestOpportunity.getArray('records');
var closeDate=LOrecs[0].get("CloseDate");
if(LatestOpportunity.size > 1){

    for(x=1;x<LatestOpportunity.size;x++)
    {
      if(LatestOpportunity.records[x].get("CloseDate")>closeDate)
      {
         closeDate=LatestOpportunity.records[x].get("CloseDate");
      }
    }
}
document.getElementById("date").innerText=closeDate;
document.getElementById("date").textContent=closeDate;
}
</script>
</head>
<body class='account' onLoad='init()'>
<DIV class="bPageBlock secondaryPalette" style="border-top:0px; border-bottom:0px; margin-bottom:0px; padding-bottom:0px">
 <DIV class=pbBody style="margin-right:0px">
 <DIV class=pbSubsection>
<div class=labelCol style="text-align:left; position:relative; left:11%; top:20%">
Last Order Date&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<span id='date'><br><br><br></div></div></div></div>
</body>

 

Greg HGreg H
Here's a different idea.
  1. Change your page layout properties for the sControl to show the label.
  2. Make the label of your sControl "Last Order Date".
  3. Alter your sControl to only display the date if one is found. (Using code below):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
 <title>Last Order Date sControl</title>
<!-- common styles --><link href="/sCSS/11.0/Theme2/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<!-- AJAX Toolkit version 11.0 --><script src="/soap/ajax/11.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
//run after page is initiated
function init() {
 var sql = sforce.connection.query("SELECT CloseDate FROM Opportunity WHERE AccountId='{!Account.Id}' ORDER BY CloseDate DESC LIMIT 1"); //query for most recent opportunity close date for this account
 if (sql.getBoolean("done") && sql.size!=0) { //if done and at least one result
  var records = sql.getArray("records"); //get an array of records from query
  var closeDate = records[0].get("CloseDate"); //assign closedate value
 } else { //otherwise no opportunities found
  var closeDate = "no opps"; //denote there are no opportunities
 }
 document.getElementById("date").innerHTML = closeDate; //display close date on page
}
//-->
</script>
</head>
<body style="background-color: #F3F3EC;" onLoad="init()">
<div id="date">Loading...</div>
</body>
</html>

By including the label of the sControl in the page layout you'll force the text to align properly regardless of resolution.

I don't usually like to rewrite someone elses code but I thought you were doing a lot of additional work in your code which could have been eliminated in the query itself.  Feel free to modify as needed.

-greg



Message Edited by Greg H on 01-08-2008 02:12 PM

Message Edited by Greg H on 01-08-2008 02:13 PM
MattLMattL
That worked perfectly.
I didn't know SOQL supported stuff like ORDER BY. That'll be a great help in the future.

Thanks a bunch!