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
zstomehzstomeh 

Expected Object

I copied the syntax below from the API samples and made a little change to read an existing field , which it did , but when reading a custom field id failed.
 
Please help.
 
========================
<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};
      sforce.connection.query(
          "Select   ContractNumber, pricing_contract_number__c  From Contract order by ContractNumber limit 30",
           callback);
  }
  function queryFailed(error, source) {
    source.output.innerHTML = "An error has occurred: " + error;
  }
  /**
  * This method will be called when the toolkit receives a successful
  * response from the server.
  * @queryResult - result that server returned
  * @source - state passed into the query method call.
  */
  function layoutResults(queryResult, source) {
    if (queryResult.size > 0) {
      var output = "";
      //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 account = records[i];
        output +=  account.ContractNumber+ "    " +   account.pricing_contract_number__c " <br>";
      }
    //render the generated html string
    source.output.innerHTML = output;
    }
  }
  </script>
  </head>
  <body onload="setupPage()">
    <div id="output"> </div>
  </body>
</html>
Frederic_DFrederic_D

Hello:

Is this field (pricing_contract_number__c) created in your Contract table in your SFDC instance?  If not, that's why it is failing.  All fields ending with __c are custom fields created by SFDC customers.

I hope this helps...

Fred

zstomehzstomeh

Frederic .. thank you, it worked... now I am trying to run a full query and it is failing... sad enough it sforce only says invalid syntax on run time, although it does say syntax is ok when I do a "check syntax"

Would you please please take a look at this code: thanks....

==============

 

<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};

sforce.connection.query(
"select Accrual_or_Additional_Discount__c,Basis__c,Branding__c, Frz_Tarrif_Date__c, Fuel_Surcharge__c, Maximum_Discount__c, Minimum_Discount__c, Misc_Comments__c, Price_Type__c, Pricing_Contract_Number__c, Pricing_Discount__c, Val__c, Val_Type__c, Waive_104__c,
Waive_IRS__c, Waive_Peak__c From Contract order by Branding__c limit 30",
callback);
}

function queryFailed(error, source) {
source.output.innerHTML = "An error has occurred - query: " + error;
}

/**
* This method will be called when the toolkit receives a successful
* response from the server.
* @queryResult - result that server returned
* @source - state passed into the query method call.
*/
function layoutResults(queryResult, source) {
if (queryResult.size > 0) {
var output = "";

//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 contract = records[i];

output +=contract.Accrual_or_Additional_Discount__c + " " + contract.Basis__c + " " + contract.Branding__c + " " + contract.Frz_Tarrif_Date__c + " " +contract.Fuel_Surcharge__c + " " + contract .Maximum_Discount__c + " " + contract .Minimum_Discount__c + " " + contract .Misc_Comments__c + " " + contract .Price_Type__c + " " + contract .Pricing_contract _Number__c + " " + contract .Pricing_Discount__c + " " + contract .Val__c + " " + contract .Val_Type__c + " " + contract .Waive_104__c + " " + contract .Waive_IRS__c + " " + contract .Waive_Peak__c + " <br>";
}

//render the generated html string
source.output.innerHTML = output;
}
}
</script>
</head>

<body onload="setupPage()">
<div id="output"> </div>
</body>
</html>

zstomehzstomeh
I had many entries in the output line of contract . instead of contract.
 
I fixed that but still not good
 
Would appreciate the help...
 
Thanks
Frederic_DFrederic_D

I tried your code on my SFDC instance but i removed all the custom fields, since i have not created them.  Instead, i just used the fields Id and Status.  It worked.  I can definetely conclude that it's a syntax/spelling of one or many custom fields...
Try a few at at time and see when it fails. 
Let me know,
Frederic
 
That's the code that i used:
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 Id, Status from Contract",
callback);

alert("end query");

}

function queryFailed(error, source)
{
 alert("QueryFailed...");
 source.output.innerHTML = "An error has occurred - query: " + error;
}

/**
* This method will be called when the toolkit receives a successful
* response from the server.
* @queryResult - result that server returned
* @source - state passed into the query method call.
*/
function layoutResults(queryResult, source)
{
 var output = "";

 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 contract = records[i];
   output += contract.Id + " " + contract.Status + " <br>";
  }

 }
  output += "ID - Status<br>";
  //render the generated html string
  source.output.innerHTML = output;
}
</script>
</head>

<body onload="setupPage()">
<div id="output"> </div>
</body>
</html>

 
zstomehzstomeh
What is an illegal URL?
Frederic_DFrederic_D

One explanation could be that your URL is not properly formed.  Meaning that, if you have parameters added to the URL, they are not properly formated.

A correct use would be:

http://www.myurl.com/page_controller?param1=data1&param2=data2

An incorrect URL would be:

http://www.myurl.com/page_controller&param1=data1&param2=data2

The first parameter name must be preceded by a question mark (?) and the following parameters must be followed by an ampersand (&).

Frederic

zstomehzstomeh
my friend, there is no URL , I created an S control, and a tab that holds the s control. whenver you open the tab it runs the s control....