+ Start a Discussion

Get the ID of a lookup field


I am trying to get the ID of a lookup field so I can populate a field on a new record. Basically I need the ID of Birth_Record__c.Dame__c instead of the value so I don't get the Malformed ID error. The line that's causing the error is in bold red. Thank you!  



var pupIn = "{!Birth_Record__c.dog_Name2__c}";
if (pupIn != "") {
alert("A dog record has already been created for this birth record. Please click the link next to Puppy Name to view that record.")
var dog = new sforce.SObject("Dog__c");

dog.Name = "{!Birth_Record__c.Name}";
dog.sex__c = "{!Birth_Record__c.Gender__c}";
dog.Dame__c = "{!Birth_Record__c.Dame__c}";

var by = "{!YEAR( DATEVALUE(Birth_Record__c.Birth__c) )}";
var bm = "{!MONTH( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bm.length == 1){
bm = "0"+bm;

var bd = "{!DAY( DATEVALUE(Birth_Record__c.Birth__c) )}";
if (bd.length == 1){
bd = "0"+bd;

var b = by+"-"+bm+"-"+bd;
dog.birthdate__c = b;

var result = sforce.connection.create([dog]);

var nextPg = result[0].id;

var newRecords = [];
var c = new sforce.SObject("Birth_Record__c");
c.id ="{!Birth_Record__c.Id}";
c.dog_Name2__c = result[0].id;
result = sforce.connection.update(newRecords);

window.location = "/" + nextPg;
alert('Could not create record '+result);


So I figured out my own, quick fix (not sure why this didn't occur to me before)... I just made a formula text field and inserted the field Birth Record > Dame > Record ID. Then I referred to that formula field for the ID. 


Thats exactly what i have been using.



Praveen Kumar Bonalu 5Praveen Kumar Bonalu 5
I have the same situtation can you please help me.I need to create a record  and update the lokkup filed on the insertion.