You need to sign in to do that
Don't have an account?

Get Unexpected element error when tyring to update case status with S-Control
I am trying to create an S-Control that updates the status of a Case to the value of the status of a bug which is a child custom object. I get the error: Unexpected element {urn:partner.soap.sforce.com}done during simple type deserialization' when I click on the link to execute the S-Control.
Here is my code:
Code:
<html> <head> <script src="/soap/ajax/9.0/connection.js"></script> <script src="/js/dojo/0.4.1/dojo.js"></script> <script> dojo.addOnLoad(init); function init() { var callback = { onSuccess : displayResult, onFailure : displayError }; var cnum = sforce.connection.query("SELECT Case__r.Id FROM SFDC_Bug__c WHERE Name = '{!SFDC_Bug__c.Name}'"); var bstatus = sforce.connection.query("SELECT Status__c FROM SFDC_Bug__c WHERE Name = '{!SFDC_Bug__c.Name}'"); var myObj = new sforce.SObject("Case"); myObj.Id = cnum; myObj.Status = bstatus; sforce.connection.update([myObj], callback); } function displayResult(result) { var it = new sforce.QueryResultIterator(result); var html = []; while(it.hasNext()) { var record = it.next(); if (record.Case__r) { html.push("Case__r.Id = " + record.Case__r.Id + "Has Been Updated!" + "<br>"); } html.push("<hr>"); html.push("<br>"); } document.getElementById("output-div").innerHTML = html.join(""); } function displayError(error) { document.getElementById("output-div").innerHTML = "oops something went wrong ... " + error; } </script> </head> <body> <div id="output-div"></div> </body> </html>
Any help would be greatly appreciated.
try :
"SELECT Case__r.Id, Status__c FROM SFDC_Bug__c WHERE Name = '{!SFDC_Bug__c.Name}'"
but, note the query call returns a struct.
cnum and bstatus are structures, not id's or strings to use in the properties of the new myObj
you should try something like this
var records = cnum.getArray('records')
records[0].Case_r.Id; // access the ID
to get the id, then the status, would be
records[0].Status__c // get the status
Here is my updated code and now I get [object Error]
Code:
can you email me directly rhess at salesforce.com
thx
Ron worked with me on this code and we got it to work. So if you are looking for a way to update the status of one object based on the status of another. This code will do just that. FYI the display results code is for troubleshooting you will probably want to replace this with code to return them to the view they were in.
Code:
Thank You Ron for all your help. I really appreciate it!
Question: We have field in opportunities that we want to auto update with the value from corresponding field in single related, custom object.
I it feasable to have this done automatically as the value changes in the custom object?