+ Start a Discussion
Connect ComputiConnect Computi 

Good basic S-Control example

Hi,
I have a couple of simple s-controls I'm taking over.  Are there any examples about how to put one-to-many items on a page?  I just want something easy for now, using just a script.  Or is it worth getting eclipse setup?

Thanks,

Roy
zachzach
Something fairly simple...

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<style type='text/css'>
body,html {
 width:100%;
 height:100%;
 margin:0;
 padding:0;
}
p {
 margin:1px;
 font-family:verdana, arial, helvetica, sans-serif;
 font-size:10px;
}
th {
 text-align:left;
}
.button {
 font-family:verdana,arial,helvetica,sans-serif;
 font-size:11px;
 font-weight:bold;
 color:#FFFFFF;
 background-color:#9096A1;
 border-top:0px;
 border-right:1px solid #5C5D61;
 border-bottom:1px solid #5C5D61;
 border-left:0px;
}
</style>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<!--<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js—browser=true;" type="text/javascript"></script>-->
<script src="http://sandbox.salesforce.com/ajax/sforceExplorer/dhtmlXCommon.js" type="text/javascript"></script>
<script src="http://sandbox.salesforce.com/ajax/sforceExplorer/dhtmlXTree.js" type="text/javascript"></script>
<script type="text/javascript" src="https://na2.salesforce.com/js/session.js"></script>
<script type="text/javascript" src="https://na2.salesforce.com/js/functions.js"></script>
<script type="text/javascript" src="https://na2.salesforce.com/js/setup.js"></script>
<script type="text/javascript" src="https://na2.salesforce.com/js/roletreenode.js"></script>
<script type='text/javascript'>

function setUser() {
 if (window.XMLHttpRequest) sforceClient.appType = Sforce.Application.Type.FireFox;
 sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0");
 sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", false);

 loadPage();
}

function loadPage() {
 dataArray = getQuery();
 var HTML = buildHTML(dataArray);
 document.getElementById("data").innerHTML = HTML;
}

function buildHTML(array) {
 var HTML = "";
 HTML += "<table width='500' border='0' cellpadding='0' cellspacing='0'>";
 HTML += "<tr>";
 HTML += "<th width='30%'><p>Id</p></th>";
 HTML += "<th width='30%'><p>First Name</p></th>";
 HTML += "<th width='30%'><p>Last Name</p></th>";
 HTML += "</tr>";
 for (var a = 0; a < array.length; a++) {
  HTML += "<tr>";
  HTML += "<td width='30%'><p>"+array[a][0]+"</p></td>";
  HTML += "<td width='30%'><p>"+array[a][1]+"</p></td>";
  HTML += "<td width='30%'><p>"+array[a][2]+"</p></td>";
  HTML += "</tr>";
 }
 HTML += "</table>";
 return HTML;
}

function getQuery() {
 var returnArray = new Array();
 var sql = new Array();
 sql = sforceClient.query("Select Id, FirstName, LastName from user where LastName = 'Smith'");
 //alert(sql);
 returnArray = buildArray(sql);
 return returnArray;
}

function buildArray(array) {
 returnArray = new Array();
 var count = 0;
 if (array.size == 0) {
  return returnArray;
 }
 if (array.done == true) {
  var batchsize = array.size;
 } else {
  var batchsize = 200;
 }
 for (var a = 0; a < batchsize; a++) {
  returnArray[count] = new Array();
  returnArray[count].push(array.records[a].get("Id"),array.records[a].get("FirstName"),array.records[a].get("LastName"));
  count++;
 }
 for (var a = 1; a < 10000; a++) {
  if (array.done == false) {
   array = sforceClient.queryMore(array.queryLocator);
   if (array.done == true) {
    var batchsize = array.size-(200*a);
   } else {
    var batchsize = 200;
   }
   for (var b = 0; b < batchsize; b++) {
    returnArray[count] = new Array();
    returnArray[count].push(array.records[b].get("Id"),array.records[b].get("FirstName"),array.records[b].get("LastName"));
    count++;
   }
  } else { break; }
 }
 return returnArray;
}


</script>
</head>
<body onLoad='setUser()'>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
 <tr style='background-color:#B7A752'>
  <td width='450' height='42' align='left' valign='middle'>
   <img src='https://na2.salesforce.com/servlet/servlet.ImageServer–oid=00D3000000002jy&id=01540000000FIGF' height='32' width='32' align='left' style='padding-left:5px;padding-right:5px;' />
   <p style='margin:0;font-size:11px;font-weight:bold;color:#FFFFFF;'>Users</p>
   <p style='margin:0;font-size:12px;font-weight:bold;color:#FFFFFF;'>People Named Smith</p>
  </td>
  <td width='450' height='42' align='right' valign='middle'>
   <p style='margin:0;font-size:10px;color:#FFFFFF;'>(change print options to landscape) <input value=' Print ' class='button' name='print2' type='button' style='width:70px;' onClick="window.print();"></p>
   <p style='margin:0;font-size:12px;font-weight:bold;color:#FFFFFF;' id='rundate'></p>
  </td>
  <td align='left' valign='middle'>&nbsp;</td>
 </tr>
</table>
<div style='height:5px;'><img height='5' /></div>
<div id='data'></div>
</body>
</html>

 

TykeTyke

Would it be possible to amend this sample so that when calling it from a custom link on a contact detail page it would take the lastname of the contact and use that in the select clause rather than having a name hardcoded?