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
Noor FazliNoor Fazli 

Malfunction on custom onclick javascript to get data from one custom related list into another custom related list

Hi,
I have a custom object(PA_Process__c) that has two related list(Revenue__c and Billing__c) defined in Master-child relationship.
I have added a custom button that executes javascript on click on Revenue related list. The purpose of this button is to move the selected record on Revenue related list to Billing related list in other words, user doesn't need to enter this info. if it already exists in Revenue. My code is able to create record in Billing__c but for some reason the values from !Revenue__c are empty. Below is my code, it looks like I'm missing something to get the datavalues from the source list(Revenue__c). Please help.
 
!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
var records={!GETRECORDIDS($ObjectType.Revenue__c)}; 
if(records[0] == null){alert("Please select atleast one row")}
else{
for (var n=0; n<records.length; n++){
try{
    var bill = new sforce.SObject("Billing__c");
    var Name = records.Name; // is empty
    bill.Name = Name; // '{!Revenue__c.Name}';
   // bill.PA__c = '{!PA_Process__c.Id}'; /
   bill.PA__c = records[n].PA__c;

  alert(records[0].Name);
  result = sforce.connection.create([bill]);

    if(result[0].success === "true"){
        location.reload();
    }
    else{
        alert(
            "An Error has Occurred. Error: " +
            result[0].errors.message
        );
    }
}
catch(e){
    alert(
        "An unexpected Error has Occurred. Error: " +
        e
    );
}
}
}


 
Rahul SharmaRahul Sharma
You are not referring to array in line Number 9. 
// Should be like this
var Name = records[n].Name;

Also what is the name variable below?
bill.Name = Name;