+ Start a Discussion

Getting Field Values from Variable in Lightning Controller

I am trying to build a page to clone a record.  I have the page and I am able to pass the current record to the new component in an attribute but I'm really struggling to figure out how I can take the values from that one record and populate x number of dummy records with the values.  I am new to javascript. 
What I have so far is the variable "CloneGS" which does get populated with the record.  I was trying to loop through x number of times (eventually, that number will also get passed from the original component) and then add a record to my attribute, "newgroupstructures" and then display these on the page so they can be edited and then created.
Any help would be greatly appreciated!!!!  thanks!!!  Fred
Here is my component:
<!-- here is the variable to hold thegroup structure that gets passed from the GroupStructures Component (that was clicked) -->
 <aura:attribute name="existinggroupstructure" type="Group_Structure__c" />
    <aura:attribute name="newGroupStructures" type="Group_Structure__c[]"/>
    <!-- Handle component initialization in a client-side controller -->
 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
 <!-- <aura:handler event="c:GSCloneRecords" action="{!c.createGS}" />  -->
    <aura:iteration items="{!v.newGroupStructures}" var="gs">
Here is my controller:
Here is my doInit controller:
doInit : function(component, event, helper) {
        //variable for the record that we are cloning from the component
        var CloneGS = component.get("v.existinggroupstructure");
 //variable to hold the new records
        var gs = [];
      //Loop through and create 5 rows with same field data in the
        for(var i = 0;i < 5;i++){
            // doesnt work.... gs.push({'Name':'Test'+i, 'Group_Number__c': testfield});
            gs.push({'Name' : 'Test'+i});

Best Answer chosen by Fred13
User-added image

All Answers

User-added image
This was selected as the best answer
Thanks for responding Rov!!!  What I am really trying to figure out is, how do I use the variable from the attribute to set the fields on the numbers variable?

I want to take the field values populated in this variable var CloneGS = component.get("v.existinggroupstructure");

and into the v.numbers attribute?


I figured it out with your  help!  Thanks so much!!!!  Last question if I may.. this is the compenent section that is rendering the values:
<aura:attribute name="newGroupStructures" type="List"/>
 <aura:iteration var="TempGS" items="{!v.newGroupStructures}">

But my values on the page are:
name: 0 Section_Code__c: 0099
name: 1 Section_Code__c: 0099

How do I now use this in a edit form that I can then create new records from?  thanks again!!!