+ Start a Discussion

Get a value from json

i  have a javascript that is querying my custom object. what i want is to get an email value. this is my javascript


var result = sforce.connection.query("Select Main_Email__c From Candidate_ATS__c where Name ='{!JobApplicant_ATS__c.Candidate_Name__c}' ");
var records = result.getArray("records");

//If there are no  record
if (records.length == 0){
alert("no record");
//If there is a record


When i alert records this is what am getting:


{type:'Candidate_ATS__c', Id:null, Main_Email__c:'abc@abc.com', }


pliz help get my email i.e. abc@abc.com


First, I would study up on javascript.


Second, I would change my alert statement to:


else {
  var record = records.length ? records[0] : records;


Also, it seems short sighted to have a where clause select, what should be a single record, based off a name.  What happens when there are two "Tom Smith" in your system?



Thank you for reply. 

You have really help me alot.

I realised that and the problem i am having is to get the parent id from the child object.

i used same query in APex code but canged Name=:JobApplicant_ATS__c.Candidate_Name__c to id=:JobApplicant_ATS__c.Candidate_Name__c in where clouse and it worked well. but in javascript its returning name instead of id so am getting invalid id.