function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Reid MaulsbyReid Maulsby 

Prepopulation help - copy information from custom object to new child custom object

Hello
 
I've read various postings on this subject, but this just isn't working for me.  I'm replace the New button on a custom object (being created from another custom object).  It's is automatically linking the two custom objects, but I'm trying to pull the Account link to the child custom object.
 
When I run the code, the URL is showing the correct IDs that I'm trying to populate, but the variables are not passing any information, and the page goes into an infinate refresh loop.
 
Here is the code that I'm running:
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<script language="JavaScript">
function redirect ()
{
parent.frames.location.replace('/a0P/e?retURL%2F{!SFDC_Acct_Plan__c.Id}&CF00NT0000000rFro_lkid={!SFDC_Acct_Plan__c.Id}');
}
redirect();
</script>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
This is setup as an HTML s-control.
 
Any and all help/insight is greatly appreciated.
Thanks
Reid
Reid MaulsbyReid Maulsby
Quick update on this...I found the 'nooverride=1' fix for the infinate loop, but I just can figure out why my field varaibles that I'm using are blank/NULL.
 
I'm creating the child custom object (Gap_Analysis__c) directly from the parent custom object (SFDC_Acct_Plan__c) screen, and I'm using the fields from the parent object.  The fields for SFDC_Acct_Plan__c should be available when I'm clicking the New button, correct?
 
Any ideas into what I'm doing wrong that this information isn't available for me to use?
 
Thanks
Reid MaulsbyReid Maulsby
Found this thread which explained that merge fields won't work between different objects.
 
 
In light of this, I needed to use a Select statement on the parent object and use the ID that was automatically pulled into the child object through the relationship to find the field information from the parent.
 
Hope this helps some people who try to use this.  If people do know of a way to have merge fields work between parent/child objects, let the rest of us know!
sfdcfoxsfdcfox
Your code works, but you need to provide the NAME of the object as well. Otherwise, the object's LKID field will be populated (actually, SAVING the record should make the link appear, assuming you don't mess with the field before saving). You need to actually include the name, though, or there will be no graphical indication that the field is populated (eg. the field appears to be blank).

Code:
<script language="JavaScript">
function redirect ()
{
parent.frames.location.replace('/a0P/e?retURL%2F{!SFDC_Acct_Plan__c.Id}&CF00NT0000000rFro_lkid={!SFDC_Acct_Plan__c.Id}&CF00NT0000000rFro={!SFDC_Acct_Plan__c.Name}');
}
redirect();
</script>
Hope this helps. Also, in the future, please use the SRC button included in the editor when pasting code; I had to reduce the page's font size to find the reply button, which happens if there's too long of a line of text anywhere in the post. Thanks!

~ sfdcfox ~
 

Message Edited by sfdcfox on 08-14-2007 08:59 AM

Reid MaulsbyReid Maulsby

Thanks sfdcfox.

So you're thinking that the merge fields should be able to work to pull a field from a parent into the child object by using that code to replace the New button?  The post I linked above is saying that it isn't possible.

To check the merge field value, I used Alert() to show the value in a pop-up, and it was showing blank for the merge fields with the Account ID and Account Name.  Any idea what I could have been doing wrong?

Here is the final code that I ended up using.  (I know this is a bit of a mess, but at least it's working for me now!  Any help on how this could be done better would be appreciated.)

Thanks again.

Code:

<html> 
<head> 
<script src="/soap/ajax/9.0/connection.js"></script> 
<script src="/js/dojo/0.4.1/dojo.js"></script> 
<script language="Javascript"> 

dojo.addOnLoad(init); 

function init() { 
var callback = { 
onSuccess : displayResult, 
onFailure : displayError 
}; 
sforce.connection.query("SELECT Account__r.Id, Account__r.Name FROM SFDC_Acct_Plan__c WHERE Id = '{!Gap_Analysis__c.Acct_PlanId__c}' LIMIT 20", callback); 
} 

function displayResult(result) { 
var it = new sforce.QueryResultIterator(result); 
while(it.hasNext()) { 
var record = it.next(); 
if (record.Account__r) { 
parent.document.location.href = "/a0P/e—nooverride=1&CF00NT0000000rFro={!Gap_Analysis__c.Acct_Plan__c}&CF00NT0000000rFro_lkid={!Gap_Analysis__c.Acct_PlanId__c}&CF00NT0000000rFsj=" + record.Account__r.Name + "&CF00NT0000000rFsj_lkid=" + record.Account__r.Id + "&retURL=%2F{!Gap_Analysis__c.Acct_PlanId__c}&Name=" + record.Account__r.Name + " - Gap Analysis"; 
} 

} 

} 

function displayError(error) { 
alert("oops something went wrong ... "); 
} 

</script> 
</head> 
<body> 
</body> 
</html>


 

NazeerNazeer
Hi,

I guess this thread is right place to put my question.. I have developed similar kind of link for my use.
But now requirement is to populate picklist value. I am copying a record by clicking button.

0xxx000xxx0xxxx={!Account.Status__c}  //  Status is picklist -This is not working.

All the picklist fields values are not populated in new record.  Any help around this highly appreciated