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
Aryama IvaturiAryama Ivaturi 

How to pass data from Aura Component to LWC


Hello Below is my code,
<aura:iteration items="{!v.dssList}" var="dss" indexVar="index">
                        <tr>
                            <td> 
                                {!index + 1}
                            </td>
                               <td>     
    	               <c:lwcCustomLookUp objectName="Service__c" fieldName="Name" selectRecordId="{!v.selectRecordId}" 
                       selectRecordName="{!v.selectRecordName}" iconName = "action:new_account" onselected="{!c.selectedRecords}"/> 
                               <lightning:input aura:id="customlookup" name="service" type="text" label="Service" value="{!dss.Service__c}" class="slds-hidden" />
                            </td>
                            <td>
                                <lightning:input name="isdatastored" type="checkbox" label="Is Data Stored" value="{!dss.Is_Data_Stored__c}" />
                            </td>
                            <td>
                                <lightning:input name="isdataprocessed" type="checkbox" label="Is Data Processed" value="{!dss.Is_Data_Processed__c}" />
                            </td>
                            <td>
                                <lightning:input name="isdatatransmitted" type="checkbox" label="Is Data Transmitted" value="{!dss.Is_Data_Transmitted__c}" />
                            </td>
                        
                            <td>
                                <a onclick="{!c.removeRowDSS}" data-record="{!index}">
                                    <lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
                                    <span class="slds-assistive-text">Delete</span>
                                </a>
                            </td> 
                        </tr>
                    </aura:iteration>



I need to pass the index value from aura iteration to custom lwc component so that I can set it uniquely . Currently for lightning input I have aura:id as customlookup. But I need to have it dynamically set so the value from custom lookup lwc is assigned to lightning input.
Below is my controller function for customlookup
selectedRecords : function(component, event, helper) {
        var selectRecName = event.getParam('selectName');
        var selectRecId = event.getParam('currentRecId');
        if(selectRecName != undefined) {
            component.set("v.selectRecordName", selectRecName);
            component.set("v.selectRecordId", selectRecId);
            alert(component);
           // var a = event.getSource();
            //var id = a.getLocalId();
            //alert(id);
            //component.find("").set("v.value", selectRecId);
            component.find("customlookup").set("v.value", selectRecId);
        }



Need help me on this.
AnudeepAnudeep (Salesforce Developers) 
Hi Aryama, 

It appears that we have to specify the lightning web component inside the aura component to pass any data to LWC
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <c:lightningCardInLwc CardTitle="lwc card"/>
</aura:component>
Here is an example: https://salesforcediaries.com/2019/09/15/pass-value-to-lwc-from-parent-aura-component/

Anudeep
Danish HodaDanish Hoda
Hi Aryama,
Plz try this:
//pass index to lwc as 
c:lwcCustomLookUp objectName="Service__c" fieldName="Name" selectRecordId="{!v.selectRecordId}" selectRecordName="{!v.selectRecordName}" iconName = "action:new_account" onselected="{!c.selectedRecords}" index="{!index}"/> 

//inside LWC js
import { LightningElement, api, track } from 'lwc'; 
export default class <className> extends LightningElement {
    @track indexVar = '';
    @api
    get index() {
        return this._index;
    }
    set index(value) {
        if(value){
            this._index = value;
            this.setIndexVar(value);
        }else{
            this._index = undefined;
        }
    }

    setIndexVar(value){
        this.indexVar = value+1;
     }
}

 
Aryama IvaturiAryama Ivaturi
Hello @Danish  and @Anudeep thanks for your response. But what I am trying  to achieve is fetch selected record data from custom lookup lwc and pass it to the lighting input below lwc component in aura component dynamically. But the lightning input requires aura id which I defined manually but not dynamically. To have it dynamically I need to use index of aura iteration.  In each an every iteration the data from lwc needs to pass down data to the lightning input below. Can you help me with that