+ Start a Discussion

AJAX Toolkit - soql query not returning value


I am trying to get value from custom object using AJAX Toolkit inside custom button javascript action. I have written following code, but not able to get any value in a variable. 

Please, have a look at a code and let me know what could be the reason.

var keyfob = new sforce.SObject("Key_Fob_Dispenser__c");
keyfob.Id = '{!Key_Fob_Dispenser__c.Id}';

var key = sforce.connection.query("select random_number__c, id, name from random_number__c  limit 1");
var records = key.getArray("records"); 
keyfob.Lock_Code__c = records[0].random_number__c;

keyfob.Lock_Code__c = records[0].random_number__c;

var result = sforce.connection.update([keyfob]);

I see that records[0].random_number__c is not returning any value.

Thanks in Advance!
Raj VakatiRaj Vakati
Hi  Jas, 
Use this line of code . I am sure your code is correct . But i guess you are getting random number value null. 

var key = sforce.connection.query("select random_number__c, id, name from random_number__c where random_number__c!=NULL  limit 1");
I am able to figure out a problem.
Variables are case-sensitive.

records[0].random_number__c should be records[0].Random_number__c