1

I want to pass "ID" Parameter as componentDef for navigateToComponent - This ID comes from lighting:outputField tag.. Below is the component code,

<aura:iteration items="{!v.Agens}" var="Agenda">

   <lightning:accordionSection name="A" label="{!Agenda.Name}" > 
   <lightning:recordViewForm  recordId="{!Agenda.Id}" objectApiName="Agenda__c" aura:id="ag">           
           <div class="slds-box slds-form_horizontal slds-container--medium slds-form slds-grid slds-wrap">                   
                    <lightning:outputField fieldName="Id" aura:id="client"/>
           </div>  
           <div>
                <li class="minli"> <h3><a onclick="{!c.navigateToSurvey}" style="width:100%;">Click here to take Survey</a></h3> </li>
           </div> 
   </lightning:recordViewForm >
  </lightning:accordionSection>
 </aura:iteration>

JS

navigateToSurvey : function(component, event, helper) 
{
        var evt = $A.get("e.force:navigateToComponent");
        var nameField = component.find("client");
        var expname = nameField.get("v.value");

        evt.setParams({
        componentDef : "c:Lightning_Survey",
        componentAttributes: 
            {
                Id : expname 
            }
        });
        evt.fire();
}, 

I am facing error

[component.find(...).get is not a function

with this.. Can anyone explain whats the issue?

2
  • what is a question? are you facing any error or exception ? maybe unexpected behavior ? – Oleksandr Berehovskyi Jan 29 '19 at 10:03
  • @OleksandrBerehovskiy , sorry for not making it clear. Just updated the error I am facing. – Vignesh Waran Jan 29 '19 at 10:08
0

Your output field is inside aura: iteration. That means there can be multiple field having aura:id 'client'

So component.find("client"); returns an array instead of just a single output field. And as the array does not have get you face the error.

A quick way would be to add an id to the anchor tag and then use the same in your navigateToSurvey method

<aura:iteration items="{!v.Agens}" var="Agenda">

   <lightning:accordionSection name="A" label="{!Agenda.Name}" > 
   <lightning:recordViewForm  recordId="{!Agenda.Id}" objectApiName="Agenda__c" aura:id="ag">           
           <div class="slds-box slds-form_horizontal slds-container--medium slds-form slds-grid slds-wrap">                   
                    <lightning:outputField fieldName="Id" aura:id="client"/>
           </div>  
           <div>
                <li class="minli"> 
                <h3><a onclick="{!c.navigateToSurvey}" id="{!Agenda.Id}" style="width:100%;">Click here to take Survey</a></h3>
                </li>
           </div> 
   </lightning:recordViewForm >
  </lightning:accordionSection>
 </aura:iteration>

JS:

navigateToSurvey : function(component, event, helper) 
{
        var evt = $A.get("e.force:navigateToComponent");
        var agendaId = event.target.id;

        evt.setParams({
        componentDef : "c:Lightning_Survey",
        componentAttributes: 
            {
                Id : agendaId 
            }
        });
        evt.fire();
}, 
3
  • Hi Pranay, It worked :) One more question - I am showing "Name" as label for lightning:accordionSection above. If I use any other custom fields, values are not showing. Is it expected.? – Vignesh Waran Jan 29 '19 at 10:41
  • are you querying other fields? does those fields exists in v.Agens? – Pranay Jaiswal Jan 29 '19 at 10:43
  • Yes, {!Agenda.Time__c} is the field I have. If possible, please have a look at salesforce.stackexchange.com/questions/247833/… :) Thanks! – Vignesh Waran Jan 29 '19 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.