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
sumpritsumprit 

How to create a S-Control with merge fields?

Hi there,

I need to create a S-Control which will display the fields (2) from the oppurtunity tab and 3 from the Accounts Object.
This Scontrol will be displayed on the Oppurtunity tab.

Any ideas how to S-controls with the merge fields?

thanks
hibarrabhibarrab
Hi

Did you solve the problem?? Now I have the same requirement. Is it possible that you help me?

Thanks

HIbarra
sumpritsumprit
I am still working on this....but as a starting point I created a S-Control that would display the data on a seperate window. The way it would be done is through the HTTP POST method which will send the data from Salesforce to an external system.

Like I said, that  I am still working on it , so I dont have a final answer for you as of yet.

thanks

sumpritsumprit

This problem is solved. Here is the code:-

<html>

<head>

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

<script>

function setupPage()

{

    //function contains all code to execute after page is rendered

  

   var state =

   {

        //state that you need when the callback is called

 

       output : document.getElementById("output"),

       startTime : new Date().getTime()

   };

 

       var callback =

       {

                   //call layoutResult if the request is successful

                  

                   onSuccess: layoutResults,

 

                  //call queryFailed if the api request fails

 

                   onFailure: queryFailed,

                   source: state

         };

 

                                        alert("start");

 

sforce.connection.query

(

 

"Select o.AccountId, o.Account.BillingCity, o.Account.BillingCountry, o.Account.BillingPostalCode, o.Account.BillingState, o.Account.BillingStreet, o.Account.Fax, o.Account.Id, o.Account.Name, o.Account.Phone, o.Account.Website, o.Id, o.Name, o.OwnerId, o.Owner.Name from Opportunity o where o.Id = '{!Opportunity.Id}' ",callback);

 

alert("end query");

}

 

function queryFailed(error, source)

 

{

 

 alert("QueryFailed...");

 

 source.output.innerHTML = "An error has occurred - query: " + error;

 

}

 

function layoutResults(queryResult, source)

 

{

 

 var output = ""; // this variable will store the data and display the results using HTTP POST method.

 

if (queryResult.size > 0)

 

 {

 

  //get the records array

 

  var records = queryResult.getArray('records');

 

 

  //loop through the records and construct html string

 

  for (var i = 0; i < records.length; i++)

 

  {

 

 var Opportunity= records[i];

 

output.requestData += "Opportunity Account ID=" + Opportunity.AccountId + "," +

 

"Opportunity Name=" + Opportunity.Name + "," +

 

"Opportunity ID=" + Opportunity.Id + "," +

 

"Account Billing City=" + Opportunity.Account.BillingCity + "," +

 

"Account Billing Country=" + Opportunity.Account.BillingCountry+ "," +

 

"Account Billing Postal Code=" + Opportunity.Account.BillingPostalCode+ "," +

 

"Account Billing State=" + Opportunity.Account.BillingState + "," +

 

"Account Billing Street=" + Opportunity.Account.BillingStreet + "," +

 

"Account Fax=" + Opportunity.Account.Fax + "," +

 

"Account ID=" + Opportunity.Account.Id + "," +

 

"Account Name=" + Opportunity.Account.Name + "," +

 

"Account Phone=" + Opportunity.Account.Phone + "," +

 

"Account Website=" + Opportunity.Account.Website + "," +

 

"Opportunity Owner ID=" + Opportunity.OwnerId + "," +

 

"Opportunity Owner Name=" + Opportunity.Owner.Name;

 

// Using HTTP POST method to send data starts here

 

sforce.connection.remoteFunction({

        url : "http://www.cheenath.com",

        onSuccess : function(response) {

            alert("Got response" + response);

        },

        onFailure : function(error) {

            alert("ERROR: " + error);

        },

        async: false

    });

 

 

  } // this is the closing for FOR loop

 

 

 } // this is the closing bracket for IF loop for records array.

 

 

  //render the generated html string

 // Comment this out if you are sending data from Salesforce to localhost.

 

  //source.output.innerHTML = output;

 

 

} // this is closing bracket for FUNCTION where you have defined OUTPUT as the variable.

 

</script>

</head>

<body onload="setupPage()">

 

<div id="output"> </div>

 

</body>

 

</html>