473,585 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble combining arrays in a table

Hi,

I'm querying Salesforce.com via their AJAX toolkit and outputting query

results into a table. Currently, their toolkit does not possess the
ability to do table joins via their structured query language, which
forces me to do the join manually via arrays.
Right now, I'm having trouble getting these query results (which are in

arrays) to combine effectively (mainly towards the end where I'm
outputting into the tables).
Any help would be greatly appreciated!
Thanks
My code looks like so:
<!--THIS QUERIES A LIST OF ACCOUNTS LABELED AS 'A LIST'--!>
var queryResult = sforceClient.qu ery("Select ID, Name,
Prospect_Status __c, SystemModstamp, Portfolio_Rank_ _c From Account
where Prospect_Status __c = 'A List' and OwnerID = '{!User_ID}'");
var accountIdCriter ia = "Where ";
for (var i=0;i<queryResu lt.records.leng th;i++) {accountIdCrite ria +=
"AccountId = '" + queryResult.rec ords[i].get("Id") + "'";
if (i < queryResult.rec ords.length - 1) {accountIdCrite ria += " or "};

}
<!--THIS QUERIES THE CONTACT TABLE FOR CONTACTS RELATED TO THE RETURNED

ACCOUNTS--!>
var contactQuery = sforceClient.qu ery("Select Id, FirstName, LastName,
AccountId From Contact " + accountIdCriter ia);

var contactIdCriter ia = "Where ";
var contactsById = [];
for (var i=0; i<contactQuery. records.length; i++) {
contactIdCriter ia += "(ContactId = '" +
contactQuery.re cords[i].get("Id") + "'" + " and IsPrimary = true)";
if (i < contactQuery.re cords.length - 1) {
contactIdCriter ia += " or "};
contactsById[contactQuery.re cords[i].get("Id")] =
contactQuery.re cords[i];

}
<!-- THIS QUERIES THE PRIMARY CONTACTS FROM THE ACCOUNTCONTACTR OLE
TABLE--!>
var roleQuery = sforceClient.qu ery("Select ContactId from
AccountContactR ole " + contactIdCriter ia);

for (var i=0;i<roleQuery .records.length ;i++) {
var roleRecord = roleQuery.recor ds[i];
var primaryContactB yAccountId = [];
var contactRecord = contactsById[roleRecord.get( "ContactId" )];
if (contactRecord) {
primaryContactB yAccountId[contactRecord.g et("AccountId" )] =
contactRecord;

}
}
var output = "<table class='sortable ' id='table1'>";
output += "<tr>";
output += "<th>Accoun t</th>";
output += "<th>Portfo lio</th>";
output += "<th>Last Activity</th>";
output += "<th>Primar y Contact</th>";
output += "</tr>";

for (var i=0; i < queryResult.rec ords.length; i++)
{
var Account = queryResult.rec ords[i];
var primaryContact = primaryContactB yAccountId[Account.get("Id ")];
var lastRow = "";
lastRow = primaryContact. get("LastName") ;
output += "<tr>";
output += "<td><a href='/"+Account.get(" Id")+"' target='NEW'>" +
Account.get("Na me") + "</a></td>";
output += "<td>" + Account.get("Po rtfolio_Rank__c ") + "</td>";
output += "<td>" + Account.get("Sy stemModstamp") + "</td>";
output += "<tdNEED TO PUT PRIMARY CONTACTS HERE </td>";
output += "</tr>";

}
output += "</table>";
document.getEle mentById("Resul tsHolder").inne rHTML = output;

Jul 27 '06 #1
1 2058
fe************@ gmail.com wrote:
Hi,

I'm querying Salesforce.com via their AJAX toolkit and outputting query

results into a table. Currently, their toolkit does not possess the
ability to do table joins via their structured query language, which
forces me to do the join manually via arrays.
Right now, I'm having trouble getting these query results (which are in

arrays) to combine effectively (mainly towards the end where I'm
outputting into the tables).
You should post an example of the objects that are being returned, then
someone might show you how to combine the arrays in the objects to
create a table. I am not going to try to reverse-engineer the objects
from your usage. :-)

[...]
var output = "<table class='sortable ' id='table1'>";
output += "<tr>";
Using the += compound operator to concatenate strings is notoriously
slow in some browsers, you are probably better to use an Array and join
it:

var output = ['<table class="sortable " id="table1">'];
output.push('<t r>')

output += "<th>Accoun t</th>";
output += "<th>Portfo lio</th>";
output += "<th>Last Activity</th>";
output += "<th>Primar y Contact</th>";
output += "</tr>";

for (var i=0; i < queryResult.rec ords.length; i++)
{
var Account = queryResult.rec ords[i];
var primaryContact = primaryContactB yAccountId[Account.get("Id ")];
var lastRow = "";
There is no need to declare the variables on every loop (it doesn't
hurt, it's just pointless). Declare them once just before the loop,
then just set their value inside. If there are many rows, it will be
faster to get the length of queryResult.rec ords just once - and set
lastRow once per loop, not twice (lastRow does not seem to be used
anywhere - should it be?):

var Account, primaryContact, lastRow;
var j = queryResult.rec ords.length;
for (var i=0; i < j; i++) {
Account = queryResult.rec ords[i];
primaryContact = primaryContactB yAccountId[Account.get("Id ")];
lastRow = primaryContact. get("LastName") ;
lastRow = primaryContact. get("LastName") ;
output += "<tr>";
[...]
document.getEle mentById("Resul tsHolder").inne rHTML = output;
... = output.join('') ;

What does output look like when you get to here, does it appear to be
valid HTML?

In most browsers, inserting a table using DOM will be just as fast,
much more reliable, standards compliant and less code than your use of
innerHTML. e.g.

var table, thead, row, cell, cellText;
table = document.create Element('table' );
table.className = 'sortable';
table.id = 'table1'
thead = table.createTHe ad();
row = thead.insertRow (-1);

for ( colTitle in {'Account':'', 'Portfolio':'',
'Last Activity':'','P rimary Contact':''}){
cell = row.insertCell(-1);
cell.appendChil d(document.crea teTextNode(colT itle));
}

var account, primaryContact, lastRow, alink;
var j = queryResult.rec ords.length;
for (var i=0; i<j; i++){
account = queryResult.rec ords[i];
primaryContact =
primaryContactB yAccountId[account.get("Id ")];
lastRow = primaryContact. get("LastName") ;
row = table.insertRow (-1);
cell = row.insertCell(-1);
alink = document.create Element('a');
alink.href = '/' + Account.get("Id ");
alink.target = 'NEW';
alink.appendChi ld(document.cre ateTextNode(acc ountName.get('N ame'));
cell.appendChil d(alink);
for (cellText in { Account.get("Po rtfolio_Rank__c "):'',
Account.get("Sy stemModstamp"): '',
"PUT PRIMARY CONTACTS HERE":''} ){
cell = row.insertCell(-1);
cell.appendChil d(document.crea teTextNode(cell Text));
}
document.getEle mentById("Resul tsHolder").appe ndChild(table);
Untested of course, but you should get the idea.
--
Rob

Jul 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3039
by: sekdab | last post by:
I am a newbie at PHP and at a loss here. I need to iterate over rows in a database, and display them as editable fields in HTML. I can do this okay. However, I then need to be able to take a 'snapshot' of all changes made and update a DB table with a single "Submit" button. Can this be done? Below is a simple example of what I'm trying to...
4
2412
by: John | last post by:
I currently have a list box that contains regions in the US (Northeast, Midwest, South, etc.). I am retrieving this data from my Region table(see below). Users have the ability to select a region as part of a search. The results were too broad so we had to make an Office table. Region Table RegionCd varchar(2) RefionDesc varchar(50)
1
1162
by: Mr. Jingles | last post by:
Hi, anyone have any thoughts on combining two 2-Dimensional arrays into one. Thanx
16
3475
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown...
1
2437
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered...
3
1478
by: loisk | last post by:
Hi, Can anybody tell me if the query below is valid in combining truncate table and insert into? " TRUNCATE TABLE tblname INSERT INTO tblname SELECT Caseid,Batch,Outcome,Spanish,Saqlang,Typecomp FROM otherTblname WHERE x=xx ;" I need to make empty one table before I add data from other table to it. Thanks!
6
3439
by: tshad | last post by:
I am looking for a way to combine 2 string arrays. I am trying to get a list of files from 2 directories and combine them: string strFiles; string strFiles2; strFiles = Directory.GetFiles(Settings.ArchiveFilePath, "*.*"); strFiles2 = Directory.GetFiles(Settings.ExceptionFilePath, "*.*");
8
1583
by: rodeored | last post by:
I don't know what the official programming lingo is for this situation but there probably is one. I have arrays, which happen to be parsed urls, and I want to make one big array with each subarray in the big array representing one directory. Sometimes the path has no sub directories, sometimes 1 or 2 etc . For example here are 2 example...
5
13336
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.