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
Excel_GeekExcel_Geek 

My first s control - can someone help the n00b?

Ok. So let's say I've built a custom object related the the Contracts object. So in the detail page for the Custom Object, I've got the Contract Number field, which displays the contract to which the object is related. This is nice, however, we really don't remember contracts by this number, but rather by the Contract Name.

Is there a way to use a custom S Control to bring the Contract Name into the custom object's detail page?

I'm not sure i even know where to start.
drogersdrogers
Did you ever get this resolved? If so would you mind telling me how.
michaelforcemichaelforce

There sure is... you can add an in-line s-control which is camouflaged to look like just another row on the detail page.  Same background color, fonts, etc as the tables used to display records.  Then simply have it query the related contract for the name (or any other field) and display it.

Excel_GeekExcel_Geek
Ok....so I've struggled through this for a bit (I know only what javascript I've picked up doing this), and here's what I've got:  It works in Firefox but not in Internet Explorer. Anyone know why?

Code:
<html>
<head>

<script type="text/javascript" src="/js/functions.js"></script>
<script language="javascript"  src="https://www.sforce.com/ajax/beta1/sforceclient.js" type="text/javascript"></script>
<script src="/soap/ajax/8.0/connection.js"></script>
<script src="/js/dojo/0.3.1/dojo.js"></script>
<script src="/soap/ajax/8.0/apex.js"></script>

<script type="text/javascript">

sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_60}");
  
function GoGetData() {
SearchString="Select Name From Contract Where ContractNumber = '{!Contract.ContractNumber}' ";

var queryResults = sforceClient.Query(SearchString);

var queryRecord = queryResults.records[0];

var DataWeGrabbed = queryRecord.get("Name");

document.getElementById("PutDataHere").innerHTML = DataWeGrabbed;
}

</script>
</head>

<body onload="GoGetData();">
<p id="PutDataHere" style="font-family: 'Arial','Helvetica',sans-serif; font-size: 75%">
</p>

</body>
</html>

 

michaelforcemichaelforce
Looks like you're doing the right things... although I would recommend switching over to the latest version of the AJAX toolkit, the beta is not supported.
 
Are you getting any errors from IE?  Or is it just blank?  I would think you have to declare that "SearchString" variable.
Excel_GeekExcel_Geek
Ok. I think I've got it. For anyone who wants to know, here's what I've done:

(Thanks, Mike, for the hints.)

Code:
<html>
<head>

<script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
<script>

function GoGetData() {
var SearchString="Select Old_Agreement_Number__c From Contract Where ContractNumber = '{!Contract.ContractNumber}' ";

var queryResults = sforce.connection.query(SearchString);

var queryRecords = queryResults.getArray('records');

for (var i = 0; i < queryRecords.length; i++) {
    var queryRecord = queryRecords[i];
    var DataWeGrabbed = queryRecord.get("Old_Agreement_Number__c");
    }

document.getElementById("PutDataHere").innerHTML = DataWeGrabbed;
}

</script>
</head>

<body onload="GoGetData();">
<p id="PutDataHere" style="font-family: 'Arial','Helvetica',sans-serif; font-size: 75%; background-color: #F3F3EC;">
</p>

</body>
</html>

 

gmc74gmc74
I am trying to figure out why this one won't work in IE but works fine in Firefox, any suggestions?


Code:
<html>
<!--
Generated by AJAX tools
Date     :  Thu Jan 17 2008 15:58:00 GMT-0700 (US Mountain Standard Time)
Template :  listview.html by manoj@cheenath.com
SControl   :  CaseTestSControl
 -->

<html>

<head><title>listview</title>

<link rel="shortcut icon" href="/favicon.ico"/>
<script src="/soap/ajax/8.0/connection.js"></script>
<script src="/js/dojo/0.3.1/dojo.js"></script>
<title>CaseTestSControl</title>

<style>
    table {
        font-family: Lucida Grande, Verdana;
        font-size: 0.8em;
        width: 100%;
        border: 1px solid #ccc;
        cursor: default;
    }

    * html div.tableContainer {
    /* IE only hack */
        width: 95%;
        border: 1px solid #ccc;
        height: 285px;
        overflow-x: hidden;
        overflow-y: auto;
    }

    table td,
        table th {
        border-right: 1px solid #999;
        padding: 2px;
        font-weight: normal;
    }

    table thead td, table thead th {
        background: #94BEFF;
    }

    * html div.tableContainer table thead tr td,
        * html div.tableContainer table thead tr th {
    /* IE Only hacks */
        position: relative;
        top: expression( dojo.html.getFirstAncestorByTag(this, 'table').parentNode.scrollTop-2);
    }

    html>body tbody.scrollContent {
        height: 262px;
        overflow-x: hidden;
        overflow-y: auto;
    }

    tbody.scrollContent td, tbody.scrollContent tr td {
        background: #FFF;
        padding: 2px;
    }

    tbody.scrollContent tr.alternateRow td {
        background: #e3edfa;
        padding: 2px;
    }

    tbody.scrollContent tr.selected td {
        background: yellow;
        padding: 2px;
    }

    tbody.scrollContent tr:hover td {
        background: #a6c2e7;
        padding: 2px;
    }

    tbody.scrollContent tr.selected:hover td {
        background: #ff3;
        padding: 2px;
    }
</style>

<script type="text/javascript">
    dojo.require("dojo.widget.SortableTable");
    dojo.addOnLoad(displayTable);


    function displayTable() {
        var query = "Select " +
                    "Id,CaseNumber,Status,Remaining__c,Route_To_User__c,Route_To_Group__c" +
                    " from Case where Status = 'New' ORDER BY Remaining__c";

        var result = sforce.connection.query(query);

        var sb = new sforce.StringBuffer();
        sb.append("<tr>");
        sb.append("<td>No</td>");
        
          sb.append("<td>Id</td>");
        
          sb.append("<td>CaseNumber</td>");
        
          sb.append("<td>Status</td>");
        
          sb.append("<td>Remaining__c</td>");
        
          sb.append("<td>Route_To_User__c</td>");
        
          sb.append("<td>Route_To_Group__c</td>");
        
        sb.append("</tr>");

        while (true) {
            if (result.size > 0) {
                for (i = 0; i < result.records.length; i++) {
                    var record = result.records[i];
                    sb.append("<tr><td>").append(i).append("</td>");
                    
                        sb.append("</td><td> ").append(editLink(record, "Id"));
                    
                        sb.append("</td><td> ").append(editLink(record, "CaseNumber"));
                    
                        sb.append("</td><td> ").append(editLink(record, "Status"));
                    
                        sb.append("</td><td> ").append(editLink(record, "Remaining__c"));
                    
                        sb.append("</td><td> ").append(editLink(record, "Route_To_User__c"));
                    
                        sb.append("</td><td> ").append(editLink(record, "Route_To_Group__c"));
                    
                    sb.append("</td></tr>");
                }
            }
            if (result.done == "true") {
                break;
            } else {
                result = sforce.connection.queryMore(result.queryLocator);
            }
        }
        document.getElementById("list-view-table").innerHTML = sb.toString();
    }


    function editLink(record, field) {
        var value = record[field];
        value = value — value : "&nbsp;";
        return value;

        //todo: edit link
        return "<a href='javascript: editCell(\"" + record.Id +
               "\",\"" + field + "\",\"" + value + "\")'>" +
               value + "</a>";
    }


    function editCell(id, field, value) {
        var newVal = prompt("Enter new text", value);
        if (newVal === null || newVal === value) {
            alert("Field not changed");
            return;
        } else {
            value = newVal;
        }
        var record = new sforce.SObject("Account");
        record.Id = id;
        record[field] = value;

        try {
            result = sforce.connection.update([record]);
            if (result[0].getBoolean("success") == false) {
                alert("update failed");
            } else {
                //initPage();
            }
        } catch (e) {
            alert("update failed");
            //sforce.debug.display(e);
        }
    }
</script>
</head>

<body>

<div class="tableContainer">

    <table dojoType="SortableTable" id="list-view-table"
           headClass="fixedHeader" tbodyClass="scrollContent"
           enableMultipleSelect="true" enableAlternateRows="true"
           rowAlternateClass="alternateRow" cellpadding="0" cellspacing="0" border="0">
    </table>
</div>

</body>
</html>

 
Thanks,

Grant