You need to sign in to do that
Don't have an account?
SrBlanco
s-control - Asset list to case detail page only works in >1 record is returned
Hi All,
Have written a s-control that returns a formatted list of assets for the account associated with a case. I have hit a problem where no results are displayed if there is only one result returned. >1 results render fine.
Code:
Any and all help is appreciated.
-Michael
Have written a s-control that returns a formatted list of assets for the account associated with a case. I have hit a problem where no results are displayed if there is only one result returned. >1 results render fine.
Code:
<html> <head> <script src="/soap/ajax/10.0/connection.js"></script> <script> function initPage() { var result = sforce.connection.query("Select Id, Name, Quantity, Support_Level__c, UsageEndDate from Asset Where AccountId = '{!Case.AccountId}' and UsageEndDate > today "); var sb = new sforce.StringBuffer(); sb.append("<b>Current Assets for {!Account.Name}</b><br>"); sb.append("<hr>"); sb.append("<center><table width=90%><tr><td>Name</td><td>Qty</td><td>Support Level</td><td>End Date</td></tr>"); while (true) { if (result.size > 0) { for (i = 0; i < result.records.length; i++) { var account = result.records[i]; sb.append("<tr>"); //<td>").append(i).append("</td>"); sb.append("</td><td> ").append(account.Name); sb.append("</td><td> ").append(account.Quantity); sb.append("</td><td><center> ").append(account.Support_Level__c); sb.append("</td><td> ").append(account.UsageEndDate); sb.append("</td></tr>"); } } if (result.done == "true") { break; } else { result = sforce.connection.queryMore(result.queryLocator); } } sb.append("</table>"); document.body.innerHTML = sb.toString(); } </script> </head> <body onload="initPage();"> </body> </html>
Any and all help is appreciated.
-Michael
Code: The QueryResultIterator automatically takes care of the queryMore, running out of records, etc. You can use this as an easy way to make sure that all records are accounted for.
It took a fair amount of trial and error but I found that these resources helped:
http://www.salesforce.com/developer/tech-notes.jsp?tn=TN-16
http://wiki.apexdevnet.com/index.php/Stylesheets_and_S-Controls_Best_Practice_Guide
Here is the code I ended up with for reference:
Hope that helps!
thanks a lot for this suggestion this helped immensely! And I have no idea how I never came across those documents!
A couple of questions..are you using Internet Explorer or Firefox? For some reason the first column where I am showing Opportunity Name is centered in IE but left centered in Firefox. Do you how to get it to display left centered in IE? Also, for those Accounts that have multiple open opportunities (which is what I am showing in this 'related list') - how do I get it to size dynamically? Currently if there are more then 3 records in the related list the user has to use a scroll bar within the section to see the other records.
thanks again!
I am not that strong of a web developer so not sure I can help on the centering issue. We pretty much use FF exclusively and I didnt even test it in IE.
As to the auto-resize thing, I think you are limited by the size of the element on your page layouts so you are stuck with the scroll bars. I put my s-control in it's own section so individuals could collapse it if they preferred.