You need to sign in to do that
Don't have an account?
Raghu_dev
Query on related object giving "Undefined" error
Hello there !!. I have a problem which I believe is so simple to resolve but I couldnt get through it.
I am doing a scontrol to display a related object data(in this case it is account object) on the child object page layout. I have all the coding working wrt to syntax and displaying the field value( if I display the ID. Like, account.Id.) If you take a look at the code i attached, it is easily understandable. But WHEN I TRY TO DISPLAY/ACCESS ANY OTHER COLUMN VALUE it is showing as undefined on scontrol. Any help from the masters out there ? And btw, as I mention on all my prev posts, i am still new to SFDC and any help is much appreciated.
Message Edited by Raghu_dev on 05-14-2008 11:57 AM
Message Edited by Raghu_dev on 05-14-2008 11:58 AM
I am doing a scontrol to display a related object data(in this case it is account object) on the child object page layout. I have all the coding working wrt to syntax and displaying the field value( if I display the ID. Like, account.Id.) If you take a look at the code i attached, it is easily understandable. But WHEN I TRY TO DISPLAY/ACCESS ANY OTHER COLUMN VALUE it is showing as undefined on scontrol. Any help from the masters out there ? And btw, as I mention on all my prev posts, i am still new to SFDC and any help is much appreciated.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/12.0/connection.js"></script> <script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script> <script type="text/javascript"> function setupPage() { var sourceId = '{!Risk__c.Id}'; 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 }; var queryString = "SELECT account__r.Id, account__r.sale_details__c FROM Risk__c WHERE Id = '" + sourceId + "'"; sforce.connection.query (queryString, callback); } function layoutResults(queryResult, source) { var output = ""; alert("Query result size " + queryResult.size); if (queryResult.size > 0) { //var describeResult = sforce.connection.describeSObject("Risk__c"); var rit = new sforce.QueryResultIterator(queryResult); var rk = rit.next(); var acntId = rk.Account__r.Id; var acntQueryString = "SELECT Id, Lease_details__c FROM Account WHERE Id = '" + acntId + "'"; var acntQueryResult = sforce.connection.query(acntQueryString); /*var ait = new sforce.QueryResultIterator(acntQueryResult); var account = ait.next(); alert ("account result set size " + account.get('Id')); //var records = queryResult.getArray('records'); output += "<table><tr><td><font size=2 color=blue>" + account.Name + "</font></td><tr></table>"; source.output.innerHTML = output; */ var records = acntQueryResult.getArray('records'); for (var i = 0; i < records.length; i++) { var account = records[i]; output += "<table><tr><td><font size=2 color=blue>" + account.lease_Details__c + "</font></td><tr></table>"; } source.output.innerHTML = output; } } function queryFailed(error, source) { alert("QueryFailed..." + error); source.output.innerHTML = "An error has occurred - query: " + error; } </script> </head> <body onload="setupPage()"> <div id="output"> </div> </body> </html>
Message Edited by Raghu_dev on 05-14-2008 11:57 AM
Message Edited by Raghu_dev on 05-14-2008 11:58 AM
The following did the magic..
var acntSaleDet = rk.Account__r.Sale_Details__c;
Thanks for all those who looked into this thread.