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
Andrew McAllisterAndrew McAllister 

How can I set the record ID for each instance of a button generated by an iteration?

I am adding a button that opens a modal window to add a task to a specific "Objective".  There is an add Task button next to every "Objective" that is displayed, but I'm not sure how I can pull the record Id of the specific objective the button sits next to so I can set the WhatId field of the task to that specific objective... Any ideas here? 

Thanks in advance.
 
<aura:iteration items="{!v.objectives}" var="obj" >


        	<div class="blacklink slds-col slds-size_11-of-12 slds-text-body_regular slds-m-bottom_small slds-box">
                	<a class ="blacklink" href="{!'/lightning/r/Task/'+ obj.Id + '/view'}" target="_blank">	{!obj.Description__c} </a>
            </div>
            <div id ="obj.Id" class="slds-size_1-of-12 slds-m-top_x-small slds-p-left_large">
                	<lightning:button label="+Task" class="slds-button slds-text-body_regular" onclick="{!c.taskopenmodal}" name="obj.Id"/>
                
			</div>
            
            	
                        <aura:if isTrue="{!obj.Tasks}">
                    	<div class="slds-col slds-size_3-of-5 slds-p-left_xx-large slds-m-bottom_small slds-text-heading_small slds-border_bottom" >
                            Task Subject
						</div>
                		<div class="slds-col slds-size_1-of-5 slds-m-bottom_small slds-text-heading_small slds-border_bottom">
                			Status
                		</div>
                		<div class="slds-col slds-size_1-of-5 slds-m-bottom_small slds-text-heading_small slds-border_bottom">
                			Owner
                		</div>
          				</aura:if>
                    
            <aura:iteration items="{!obj.Tasks}" var="t" >
                       	<div class="slds-col slds-size_3-of-5 slds-p-left_xx-large slds-m-bottom_small" >
                            <a href="{!'/lightning/r/Task/'+ t.Id + '/view'}" target="_blank">
                            {!t.Subject} 
                            </a>
						</div>
                		<div class="slds-col slds-size_1-of-5 slds-m-bottom_small">
                			{!t.Status}
                		</div>
                		<div class="slds-col slds-size_1-of-5 slds-m-bottom_small">
                			{!t.Owner.Name}
                		</div>
            </aura:iteration> 
            
         </aura:iteration>

 
Best Answer chosen by Andrew McAllister
Naveen IlaNaveen Ila
We can get the Objective id by using below code. However while populated the name field on the button you haven't use merge field expression.
i.e., {!obj.Id} instead you used obj.Id
Using event.getSource().get("v.name"); 

<lightning:button label="+Task" class="slds-button slds-text-body_regular"onclick="{!c.taskopenmodal}" name="obj.Id"/>  change the highlited to merge field expression.
 

All Answers

Naveen IlaNaveen Ila
We can get the Objective id by using below code. However while populated the name field on the button you haven't use merge field expression.
i.e., {!obj.Id} instead you used obj.Id
Using event.getSource().get("v.name"); 

<lightning:button label="+Task" class="slds-button slds-text-body_regular"onclick="{!c.taskopenmodal}" name="obj.Id"/>  change the highlited to merge field expression.
 
This was selected as the best answer
VAIBHAV SRIVASTAVA 48VAIBHAV SRIVASTAVA 48
Hi Andrew,
I am also stucked in similar type of task, I have a Edit button against ech iterated Claim, Now I want that If I click on Edit button against Claim-1 then only the Claim-1 should become editable.
Please guide me how to achieve this ?
Thanks 

Vaibhav
Miles Smith 5Miles Smith 5
Am facing the same problem. Hope anyone here can help me too. Thanks in advance.
 Regards,
ViaMichelin (https://viamichelin.onl/) PutLocker  (https://putlocker.ooo/) Google Earth (https://googleearth.onl/)