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

S-Control to show Aggregate Data
Hi,
I am trying to create a custom S-Control for the following situation. I have a custom field called Forecast GP on the Opportunity object. Opportunities are tied to Accounts via the standard loopup Account field at the Opportunity object level.
I need to show a roll up of Forecast GP on the Account Details page. Salesforce does not allow a rollup field on the Account object over Opportunity data. It only allows for rollups with the Relationship Assessments object.
So, my question is, how can I create a custom s-control to roll-up the Forecast GP data of Opportunities? This would display on the Account Details page.
Is there any example code showing something similar?
Thanks so much,
Joanna
I am trying to create a custom S-Control for the following situation. I have a custom field called Forecast GP on the Opportunity object. Opportunities are tied to Accounts via the standard loopup Account field at the Opportunity object level.
I need to show a roll up of Forecast GP on the Account Details page. Salesforce does not allow a rollup field on the Account object over Opportunity data. It only allows for rollups with the Relationship Assessments object.
So, my question is, how can I create a custom s-control to roll-up the Forecast GP data of Opportunities? This would display on the Account Details page.
Is there any example code showing something similar?
Thanks so much,
Joanna
<html>
<head>
<script type="text/javascript" src="/soap/ajax/10.0/connection.js"></script>
<script text="javascript">
var aid="{!Account.Id}";
//function initiated after page load
function initPage() {
var j = ""; //declaration of variable j
var ForecastGPSum = 0.00;
var ForecastSalesSum = 0.00;
var ForecastGPPercent = 0;
var soql = sforce.connection.query("SELECT Forecast_GP__c, Forecast_Sales__c FROM Opportunity WHERE AccountId='"+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].Forecast_GP__c+"<br>";
j += CurrencyFormatted(records[i].Forecast_GP__c) + ", ";
ForecastGPSum = parseFloat(ForecastGPSum) + parseFloat(records[i].Forecast_GP__c);
ForecastSalesSum = parseFloat(ForecastSalesSum) + parseFloat(records[i].Forecast_Sales__c);
}
if (ForecastSalesSum == 0 )
{
ForecastGPPercent = 0;
}
else
{
ForecastGPPercent = CurrencyFormatted((ForecastGPSum / ForecastSalesSum) * 100);
}
document.getElementById("results").innerHTML = "Forecast Sales: $" + CommaFormatted(ForecastSalesSum) + "<BR>Forecast GP: $" + CommaFormatted(ForecastGPSum) + "<BR>Forecast GP %: " + ForecastGPPercent +"%"; }
function CommaFormatted(amount)
{
var delimiter = ","; // replace comma if desired
var a = CurrencyFormatted(amount).split('.',2)
var d = a[1];
var i = parseInt(a[0]);
if(isNaN(i)) { return ''; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
var n = new String(i);
var a = [];
while(n.length > 3)
{
var nn = n.substr(n.length-3);
a.unshift(nn);
n = n.substr(0,n.length-3);
}
if(n.length > 0) { a.unshift(n); }
n = a.join(delimiter);
if(d.length < 1) { amount = n; }
else { amount = n + '.' + d; }
amount = minus + amount;
return amount;
}
function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
</script>
</head>
<body onload="initPage();">
<div id="results">Loading...</div>
</body>
</html>