+ Start a Discussion
QotDQotD 

Get the ID of a lookup field

Hi,

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!  

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

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.")
}else{
var dog = new sforce.SObject("Dog__c");

dog.Name = "{!Birth_Record__c.Name}";
dog.sex__c = "{!Birth_Record__c.Gender__c}";
alert("{!Birth_Record__c.Dame__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]);

if(result[0].getBoolean("success")){
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;
newRecords.push(c);
result = sforce.connection.update(newRecords);

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

QotDQotD

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. 

SoleesSolees

Thats exactly what i have been using.

 

cheers

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.