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
benfishinbenfishin 

Ajax Beta1 S-Control Help

Can I not do a get and set with the same retrieve object? Does not update the Status.
 
  //Get Salesforce connection based on users current session id
    sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
    window.setTimeout(";", 1000);   
 var orderIds = new Array();
    orderIds[0] = "{!Order_ID}";
    var orderRetrieve = sforceClient.Retrieve("AccountId, Status", "Order", orderIds);
if(orderRetrieve[0] != null) {
   var orderAccountId = orderRetrieve[0].get("AccountId");
alert("AccountId - " + orderAccountId);
alert("Status - " + orderRetrieve[0].get("Status"));
    orderRetrieve[0].set("Status", "5 - Completed");
alert("Status - " + orderRetrieve[0].get("Status"));
    sforceClient.Update(orderRetrieve);
}
SteveBowerSteveBower

Without looking too carefully, in your code, orderRetrieve isn't a single Dynabean which can be used in an update.  It's an array.

Steve Bower

benfishinbenfishin

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Complete Order</title>

<script src="https://www.sforce.com/ajax/beta1/sforceclient.js" type="text/javascript"></script>
<link href="/css/ie_global.css" rel="stylesheet" type="text/css">
<link href="/css/ie_navigation.css" rel="stylesheet" type="text/css">
<link href="/css/opportunities_styles.css" rel="stylesheet" type="text/css">
<script language="javascript">

function initPage() {
    //Get Salesforce connection based on users current session id
    sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
    window.setTimeout(";", 1000);
  
  if ("{!Order_StatusCode}" == "Activated" && "{!Order_Status}" != "5 - Completed") {
    var orderQueryResult = sforceClient.Query("SELECT AccountId, Status FROM Order WHERE Id = '{!Order_ID}'");
       if (orderQueryResult.size == 1) {
        outputDebug(orderQueryResult);
       var order = orderQueryResult.records[0]
       alert(order.get("AccountId"));
       var orderAccountId = order.get("AccountId");
        alert("AccountId - " + orderAccountId);
        alert("Status - " + order.get("Status"));
        order.set("Status", "5 - Completed");
        alert("Status - " + order.get("Status"));
        var upateResults = sforceClient.Update(orderQueryResult.records);
       outputDebug(upateResults);
       } else { 
         //outputDebug(orderBean);
      }
  } else {
    errorMsg = "";
      if (orderStatus == "5 - Completed") {
      errorMsg = "The Order is already completed.";
    } else { 
       errorMsg = "The Order is not Activated.";
          outputError(errorMsg);
    }
  }
}

/**
This function takes an error string and outputs it to the named div
in the html page so the user knows what went wrong.
*/
function outputError(error) {

    output = "<br><br>";
    output += "<span style=\"font-weight: bold; font-size: 12pt; font-family: 'Arial', 'Helvetica';\">";
    output += "Error:"
    output += "</span><br>";
    output += "<span style=\"font-weight: normal; font-size: 10pt; font-family: 'Arial', 'Helvetica';\">";
    output += error;
    output += "</span><br>";

    document.getElementById("divErrorMsg").innerHTML = output;
    document.getElementById("divErrorMsg").style.display = "";

}

/**
This function is for reference and use if you wish to modify the code and use it to
help debug your changes. It is currently not called from the sample at the time it was
distributed.
*/
function outputDebug(msg) {
    document.getElementById("divDebugMsg").innerHTML = "<h1>DEBUG</h1><h2>" + msg + "</h2>";
    document.getElementById("divDebugMsg").style.display = "";
}


</script>
</head>
<body onload="initPage();">
<DIV id="divErrorMsg"></DIV>
<DIV id="divDebugMsg"></DIV>
</body>
</html>


 

Still getting an issue with set/update of the dynaBean the upateResults displays:

 

id: success: false errors fields autoNumber: false byteLength: 0 calculated: false createable: false custom: false defaultedOnCreate: false digits: 0 filterable: false label: length: 0 name: nameField: false nillable: false picklistValues: precision: 0 referenceTo: restrictedPicklist: false scale: 0 soapType: type: updateable: false message: invalid cross reference id statusCode: INVALID_CROSS_REFERENCE_KEY

Thanks for any suggestions,

-Benj


 

benfishinbenfishin

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Complete Order</title>

<script src="https://www.sforce.com/ajax/beta1/sforceclient.js" type="text/javascript"></script>
<link href="/css/ie_global.css" rel="stylesheet" type="text/css">
<link href="/css/ie_navigation.css" rel="stylesheet" type="text/css">
<link href="/css/opportunities_styles.css" rel="stylesheet" type="text/css">
<script language="javascript">

function initPage() {
    //Get Salesforce connection based on users current session id
    sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
    window.setTimeout(";", 1000);
  
  if ("{!Order_StatusCode}" == "Activated" && "{!Order_Status}" != "5 - Completed") {
    var orderQueryResult = sforceClient.Query("SELECT Id, AccountId, Status FROM Order WHERE Id = '{!Order_ID}'");
       if (orderQueryResult.size == 1) {
        outputDebug(orderQueryResult);
       var order = orderQueryResult.records[0]
       alert(order.get("AccountId"));
       var orderAccountId = order.get("AccountId");
        alert("AccountId - " + orderAccountId);
        alert("Status - " + order.get("Status"));
        order.set("Status", "5 - Completed");
        alert("Status - " + order.get("Status"));
        var upateResults = sforceClient.Update(orderQueryResult.records);
       outputDebug(upateResults);
       } else { 
         //outputDebug(orderBean);
      }
  } else {
    errorMsg = "";
      if (orderStatus == "5 - Completed") {
      errorMsg = "The Order is already completed.";
    } else { 
       errorMsg = "The Order is not Activated.";
          outputError(errorMsg);
    }
  }
}

/**
This function takes an error string and outputs it to the named div
in the html page so the user knows what went wrong.
*/
function outputError(error) {

    output = "<br><br>";
    output += "<span style=\"font-weight: bold; font-size: 12pt; font-family: 'Arial', 'Helvetica';\">";
    output += "Error:"
    output += "</span><br>";
    output += "<span style=\"font-weight: normal; font-size: 10pt; font-family: 'Arial', 'Helvetica';\">";
    output += error;
    output += "</span><br>";

    document.getElementById("divErrorMsg").innerHTML = output;
    document.getElementById("divErrorMsg").style.display = "";

}

/**
This function is for reference and use if you wish to modify the code and use it to
help debug your changes. It is currently not called from the sample at the time it was
distributed.
*/
function outputDebug(msg) {
    document.getElementById("divDebugMsg").innerHTML = "<h1>DEBUG</h1><h2>" + msg + "</h2>";
    document.getElementById("divDebugMsg").style.display = "";
}


</script>
</head>
<body onload="initPage();">
<DIV id="divErrorMsg"></DIV>
<DIV id="divDebugMsg"></DIV>
</body>
</html>


 
Ahhh. Must have object Id to know what to Update (see code change above). Now I have a new issue. One of the return values is not updatable (AccountId). Is there a good practice for doing this in one call (i.e. maybe removing AccountId from message) instead of making two calls one for Status (updatable) and the other for AccountId (not updatable)?

 

PradPrad
I am a Salesforce newbie. I am using a very similar code to update one of my custom object records. When I call sforceClient.Update, I get below error in updateResults, and value does not get updated. Can you help?

faultstring:java.lang.NumberFormatException: empty string

faultcode: soapenv: Server

 

Code Excerpt:

var BQWName = "{!Business_Qualification_Worksheet_Name}";

var qr = sforceClient.Query("Select Name,AD_Client_manager__c, Additional_Details__c, Date_and_Time__c, Id, Opportunity__c, PL_s_Affected__c, Potential_Profit_Margin__c, Potential_Project_Amount__c, Proposal_Submission_Date__c, Q1_answers__c, Q1_Notes__c, Q10_answers__c, Q10_Notes__c, Q2_answers__c, Q2_Notes__c, Q3_answers__c, Q3_Notes__c, Q4_answers__c, Q4_Notes__c, Q5_answers__c, Q5_Notes__c, Q6_answers__c, Q6_Notes__c, Q7_answers__c, Q7_Notes__c, Q8_answers__c, Q8_Notes__c, Q9_answers__c, Q9_Notes__c, Total_Score__c from Business_Qualification_Worksheet__c where Name = '" + BQWName + "'");

if (qr.getClassName() == "QueryResult")

{

if (qr.size == 1)

{

alert("Inside qr.size")

var BQW = qr.records[0]

var BQWName = BQW.get("Name");

alert("BQWName - " + BQWName);

alert("AD Manager - " + BQW.get("AD_Client_manager__C"));

BQW.set("AD_Client_manager__C", "ADMgr");

alert("AD Manager now - " + BQW.get("AD_Client_manager__C"));

var updateResults = sforceClient.Update(qr.records);

alert(updateResults);

 }

 }

benfishinbenfishin
I would try removing the fields from your SOQL query that you are not updating. I had a similar issue with a non-updateable field.