I have below code which throws an error to populate lookup field ID value from one object to another. It unexpectedly tries to assign Name of Account object instead of ID. So it throws error. Can someone tell me why?
Javascript Code
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
//identify parent record
var FormR= new sforce.SObject("Form_Requests_abv__c");
FormR.id = '{!Form_Requests_abv__c.Id }';
FormR.name = '{!Form_Requests_abv__c.Name}';
// insert Sample Form transactions
var SampleFormTrans= new sforce.SObject("Sample_Order_Form_abv__c");
//SampleFormTrans.Account_abv__c = "{!Form_Requests_abv__c.Account_abv__c}";
var s= document.getElementById('{!Form_Requests_abv__c.Account_abv__c}');
SampleFormTrans.Account_abv__c = s;
var add= document.getElementById('{!Form_Requests_abv__c.Address_abv__c}');
//SampleFormTrans.Address_abv__c= '{!Form_Requests_abv__c.Address_abv__c}';
SampleFormTrans.Address_abv__c= add;
var FR= document.getElementById('{!Form_Requests_abv__c.Id}');
SampleFormTrans.Form_Request_abv__c= FR;
//SampleFormTrans.Form_Request_abv__c= '{!Form_Requests_abv__c.Id}';
SampleFormTrans.OwnerID= '{!Form_Requests_abv__c.OwnerId}';
SampleFormTrans.Quantity_abv__c= '{!Form_Requests_abv__c.Quantity_abv__c}';
//SampleFormTrans.Product_abv__c='{!Form_Requests_abv__c.Product_ID_abv__c}';
//SampleFormTrans.Form_template_abv__c='{!Form_Requests_abv__c.Form_Template_Name_abv__c}';
var FT= document.getElementById('{!Form_Requests_abv__c.Form_Template_Name_abv__c}');
SampleFormTrans.Form_Template_Name_abv__c= FT;
//get query
var query = "SELECT Account_abv__c ,Address_abv__c,Form_Request_abv__c, "+
"OwnerID, Quantity_abv__c, Product_abv__c, Form_template_abv__c, Id FROM "+
"Sample_Order_Form_abv__c WHERE Form_Request_abv__c='{!Form_Requests_abv__c.Id}'";
var records = sforce.connection.query(query);
alert(records);
var records1 = records.getArray('records');
alert(records1);
if(records[0]==null)
{alert('New record to insert');
var result = sforce.connection.create([SampleFormTrans]);}
if(result[0].getBoolean("success"))
{
alert('Sample Form Transaction inserted successfully');
window.location.reload();
}
else{
alert('Error : '+result);
}
var formId = '{!Sample_Order_Form_abv__c.Id}';
var expired = '{!Sample_Order_Form_abv__c.Expired_abv__c}';
var templateId = '{!Sample_Order_Form_abv__c.Form_template_Id_abv__c}';
if(expired == '1'){
alert("Form expired. Print option not available.");
}else{ window.open('/apex/FormTemplatePrinter?ids='+formId+'&TemplateId='+templateId,'_blank');
}
Error
Successfully created but all lookup field values are blank.
var query = "SELECT Account_abv__c ,Address_abv__c,Form_Request_abv__c, OwnerID, Quantity_abv__c, Product_abv__c, Form_template_abv__c, Id FROM Sample_Order_Form_abv__c WHERE Form_Request_abv__c='{!Form_Requests_abv__c.Id}'";