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
RKRK 

Displaying Query Results in In-Line SControl...

Hey all,
I've seen examples where some query results could be displayed in an Inline-SControl on a page.

For example, I could have a custom object called "Business Plan".   Within the Custom Object, there could be a section that calls an SControl that goes out, grabs the first name, last name, phone number and total sales for all producers that have a custom field of "Tier" flagged as an "A".  The contents of this section would change as the people who are tagged as A's change. 

I thought that there was something in the DreamForce 06 presentations (SControls for Dummies, for example), but I couldn't find anything.  Also, I seem to recall that there was an SF.com app out on the AppExchange that essentially did this, but I couldn't find it, either (The Mass Update Opportuntiies in some ways does it, but it is much more complex that my needs)..I thought that it was a mass view of contacts, but I might be wrong.  And I recall the foundation being the use of the SF.com Style Sheets.

Wondering if anyone has the same recollection as me.  As I have done many times in the past (with all of your help), I plan on re-engineering the existing code to fit the specific needs of my users.

Thanks much for any insight...
RK

P.S.  If you are like me and you don't have the knowledge to do coding on your own and you rely on reverse engineering other people's code, please vote on my Idea below.  Thanks!
http://ideas.salesforce.com/article/show/57416/A_UserSubmitted_CodeSControlEnhancement_Sample_Library

Message Edited by RK on 04-19-2007 08:26 AM

RKRK
So, I found the AppExchange package that queried the text..it was an old, private one that I had access to.

I went and modified (some might say bastardized :smileyvery-happy:) the code, and have at least been able to
get the resultant data to output to the screen.  For the life of me, I can't get the style sheet to apply.  Code is below. Any input would be happily and gratefully received.

Humbly,
RK

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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">

<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

<title></title>

<!-- Next is a simple stylesheet for results display - also uses the standard SFDC css, see link refs above-->

<style type="text/css">
TH {background-color: yellow; color: white}
TD.markerFont {background-color: yellow; color: white}
span.GRMsummaryTxt {font-weight: bold}
</style>

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

<script>

var externalWholesalerId = '{!$User.Id}';
function createTable(){
//below is the relatively simple query to determine which contacts should be displayed
var queryContact = sforce.connection.query("Select Id, X2007_Resultant_Sales_Goal__c, X2007_Resultant_Sales__c, OwnerId, Full_Name__c from Contact where X2006_Rank_Within_Region__c > 0 and X2006_Rank_Within_Region__c < 51 and Known_Terminated__c = FALSE and OwnerID = '"+externalWholesalerId+ "' " );

var contactRecordsLength = queryContact.getArray("records");

var totalcontactsToBeAdded = contactRecordsLength.length;

contactsToBedisplayed = queryContact.getArray("records");

var contactsToBedisplayedArray= new Array();

var recordsContact = queryContact.getArray('records');

for (var i = 0; i < recordsContact.length; i++)
{ //
alert ("in if loop");
alert("i equals " + i);

if (i==0) {  //creates header row for table
htmlstr="<DIV><TABLE width=100% class=list border=0>";
htmlstr+="<tr class=headerRow height=20><TH>Name</TH><TH>Address</TH><TH>Result</TH><TH>Returned</TH><TH>Coords (Lat,Lng)</TH><TH>Accuracy</TH></TR>";
}
taskCreatedLineItem = contactsToBedisplayed[i];
var conId = taskCreatedLineItem .get("Id");
var resultantSales = taskCreatedLineItem .get("X2007_Resultant_Sales__c");
var resultantSalesGoal = taskCreatedLineItem .get("X2007_Resultant_Sales_Goal__c");
var fullName = taskCreatedLineItem .get("Full_Name__c");
var ownerId = taskCreatedLineItem .get("OwnerId ");
alert ("Contact ID is " + conId);
//below appends contact data to table.  Not yet complete, but works in concept.
htmlstr+="<TR><TD><A target='_blank' HREF='/"+conId+"'>"+fullName+"</TD><TD>"+resultantSales+"</TD><TD>Success</TD><TD>"+resultantSalesGoal+"</TD><TD>"+conId+"</TD><TD>"+conId+"</TD></TR>";
}
htmlstr+="</TABLE></DIV>";
//innerHTML=htmlstr;
alert ("Out of if statement. Resultant HTML code is:" + htmlstr);
document.write(htmlstr); //outputs to screen....would like to have this data formatted per stylesheet
}

</script>

</head>

<body onload="createTable();">

</body>
</html>
Execute EZSAASExecute EZSAAS

RK,
A great tutorial is available on ADN  
you need to specify the body class and top level DIV to get the main look & feel. You may also need to apply content DIVs to your table.

Code excerpt for (account) example is below
(Please use SRC button to insert code in the community postings, or it is difficult to view your post, it askews formatting!)

Code:

<BODY class="account">


 <DIV class=bPageTitle>
 <DIV class="ptBody secondaryPalette">
 <DIV class=content><IMG class=pageTitleIcon alt=Account src="/s.gif">
 <H1 class=pageType>Account<SPAN class=titleSeparatingColon>:</SPAN></H1>
 <H2 class=pageDescription>Search Page</H2>
 </DIV></DIV></DIV>


 <DIV class="bPageBlock secondaryPalette">
 <DIV class=pbBody>
 <DIV class=pbSubsection>
<!-- your createTable() output goes here -->
</DIV></DIV></DIV>

 

RKRK
EZSAAS,
Thanks so much for the link to that tutorial.  It was exactly what I needed, and I was able to get my formatting as
I wanted it. 

I have run into another issue, however - I am primarly returning contact data - name, phone number, mailing city,
etc.  But, I am also looking to return the Account Name for the contact.  My query code is listed below:

Code:
var queryContact = sforce.connection.query("Select ID, AccountId, MailingCity, Phone, X2007_Resultant_Sales_Goal__c, X2007_Resultant_Sales__c, Full_Name__c,  Account.ID, Account.Name FROM CONTACT  where Tier__c = 'A' and Known_Terminated__c = FALSE  and OwnerID = '"+externalWholesalerId+ "' " );

Further in the code, I extract the values for the individual fields, as shown here:
Code:
var conId = taskCreatedLineItem .get("Id");
var resultantSales = taskCreatedLineItem .get("X2007_Resultant_Sales__c");
var resultantSalesGoal = taskCreatedLineItem .get("X2007_Resultant_Sales_Goal__c");
var fullName =  taskCreatedLineItem .get("Full_Name__c");
var ownerId = taskCreatedLineItem .get("OwnerId ");
var contactAccountID =  taskCreatedLineItem .get("Account.ID");
var contactAccountName = taskCreatedLineItem .get("Account.Name");
var contactPhone = taskCreatedLineItem .get("Phone");
var contactCity = taskCreatedLineItem .get("MailingCity");

Everything  generates correctly, with the exception of the Account Name or the Account ID (doesn't matter which I
choose to display) - they both come back with a NULL value. 

From what I have read, I beleive that I might need to use QueryResultIterator?  Does that seem logical?

I've run the query within AjaxTools, and I see that it use used in the "Generate Sample" code, but I'm not certain
if that is only needed because I'm pulling a field from the related Account.

Am I barking up the right tree?
Thanks,
RK

 

 


cheenathcheenath

Try this:
var contactAccountName = taskCreatedLineItem.Account.Name;

This will also work:
taskCreatedLineItem.get("Account").get("Name");
HTHs,





RKRK
Perfect...worked like a charm.  Thanks for the pointer!

For those of you who are code challened like me, the result is below.  It might not be pretty, but it works.

Thanks to all...and should you have a desire for a sample code library for examples like this, please vote on my idea out on ideas.salesforce.com:
http://ideas.salesforce.com/article/show/57416/A_UserSubmitted_CodeSControlEnhancement_Sample_Library

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" >

<HTML>

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

<script>

var externalWholesalerId = '{!FID_Business_Plan__c.RSMId__c}';

function num2money(n_value) {

// validate input
if (isNaN(Number(n_value)))
return 'ERROR';

// save the sign
var b_negative = Boolean(n_value < 0);
n_value = Math.abs(n_value);

// round to 1/100 precision, add ending zeroes if needed
var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

// separate all orders
var b_first = true;
var s_subresult;
while (n_value > 1) {
s_subresult = (n_value >= 1e3 — '00' : '') + Math.floor(n_value%1e3);
s_result = s_subresult.slice(-3) + (b_first – '.' : ',') + s_result;
b_first = false;
n_value = n_value/1e3;
}
// add at least one integer digit
if (b_first)
s_result = '0.' + s_result;

// apply formatting and return
return b_negative
˜ '($' + s_result + ')'
: '$' + s_result;
}

function createTable() {
var queryContact = sforce.connection.query("Select ID, Change_Tier__c, AccountId, MailingCity, Phone, X2007_Resultant_Sales_Goal__c, X2007_Resultant_Sales__c,X2006_Resultant_Sales__c, Full_Name__c, Account.ID, Account.Name FROM CONTACT c where c.Tier__c = 'A' and c.Known_Terminated__c = FALSE and c.OwnerID = '"+externalWholesalerId+ "' order by X2006_Resultant_Sales__c desc" );

var contactRecordsLength = queryContact.getArray("records");

var totalcontactsToBeAdded = contactRecordsLength.length;

contactsToBedisplayed = queryContact.getArray("records");

var contactsToBedisplayedArray= new Array();

var recordsContact = queryContact.getArray('records');

for (var i = 0; i < recordsContact.length; i++)
{ //
//alert ("in if loop");
//alert("i equals " + i);

if (i==0) {
htmlstr="<TABLE width=100% class=list border=0>";
htmlstr+="<tr class=headerRow height=20><TH>Name</TH><TH>Account</TH><TH>Phone</TH><TH>Mailing City</TH><TH>2006 Resultant $</TH><TH>2007 Resultant $</TH><TH>2007 Resultant $ Goal</TH></TR>";
}
taskCreatedLineItem = contactsToBedisplayed[i];
var conId = taskCreatedLineItem .get("Id");
//var resultantSales = taskCreatedLineItem .get("X2007_Resultant_Sales__c");
var resultantSales2007a = taskCreatedLineItem .get("X2007_Resultant_Sales__c");
var resultantSales2007b = Math.round(resultantSales2007a);
var resultantSales2007 = num2money(resultantSales2007b);
var resultantSales2006a = taskCreatedLineItem .get("X2006_Resultant_Sales__c");
var resultantSales2006b = Math.round(resultantSales2006a);
var resultantSales2006 = num2money(resultantSales2006b);
//var resultantSalesGoal = taskCreatedLineItem .get("X2007_Resultant_Sales_Goal__c");
var fullName = taskCreatedLineItem .get("Full_Name__c");
var ownerId = taskCreatedLineItem .get("OwnerId ");
var contactAccountID = taskCreatedLineItem .get("Account.ID");
var contactAccountName = taskCreatedLineItem.get("Account").get("Name");
var contactPhone = taskCreatedLineItem .get("Phone");
var contactCity = taskCreatedLineItem .get("MailingCity");
var changeTier = taskCreatedLineItem .get("Change_Tier__c");

if ((taskCreatedLineItem.get("X2007_Resultant_Sales_Goal__c")) == null ) {
var resultantSalesGoal = '-';}
else
{
var resultantSalesGoala = (taskCreatedLineItem.get("X2007_Resultant_Sales_Goal__c"));
var resultantSalesGoalb = Math.round(resultantSalesGoala);
var resultantSalesGoal = num2money(resultantSalesGoalb);
}

// end if, populate 1st row
htmlstr+="<TR><TD><A target='_blank' HREF='/"+conId+"'>"+fullName+"</TD><TD>"+contactAccountName+ "</TD><TD>"+contactPhone+"</TD><TD>"+contactCity+"</TD><TD>"+resultantSales2006+"</TD><TD>"+resultantSales2007+"</TD><TD>"+resultantSalesGoal+"</TD></TR>";
}
htmlstr+="</TABLE>";
document.getElementById("ResultsHolder").innerHTML = htmlstr;
//alert ("Out of if statement. Resultant HTML code is:" + htmlstr);
}

</script>
<BODY class="account" onload="createTable();">

<div id="ResultsHolder"></div>

</DIV></DIV></DIV>
</BODY>
</HTML>