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
VSK98VSK98 

How to get Aura:Method Attributes in JS Controller

<aura:method name="myMethod" action="{!c.executeMyMethod}">
     	<aura:attribute name="Cname" type="string" default="test"/> 
        <aura:attribute name="city" type="string" /> 
         <aura:attribute name="Assetcnt" type="string" />
         <aura:attribute name="CustomerId" type="string" />
         <aura:attribute name="children" type="list" />
         </aura:method>

Hi All,

I have created the Aura: Method tag, under I declared few attributes with default values. When i am trying to access the attributes with their name getting UNDEFINED values.

Aura: Method
<aura:method name="myMethod" action="{!c.executeMyMethod}">
     	<aura:attribute name="Cname" type="string" default="test"/> 
        <aura:attribute name="city" type="string" /> 
         <aura:attribute name="Assetcnt" type="string" />
         <aura:attribute name="CustomerId" type="string" />
         <aura:attribute name="children" type="list" />
         </aura:method>

JS Controller:
executeMyMethod : function(component, event, helper) {
         console.log('Beforeset: '+ component.get("v.myMethod"));  --- Undefined
          console.log('Beforeset: '+ component.get("v.Cname")); --- Undefined
         console.log('Beforeset: '+ component.get("v.myMethod.Cname")); --- Undefined
}

Regards,
VSK98​​​​​​​

 
VSK98VSK98
Hi Arun,

I have tried with your code but unable to set the value into another attribute
executeMyMethod : function(component, event, helper) {
        
        var params = event.getParam('arguments');
          
         console.log('name: '+ params.name);
         console.log('city: '+ params.city);
        
      
         console.log('Beforeset: '+ component.get("v.myMethod")); ---- Undefined
          console.log('Beforeset: '+ component.get("v.Cname")); ---- Undefined
         console.log('Beforeset: '+ component.get("v.myMethod.Cname")); ---- Undefined
         
        component.set("v.Cname",params.name); --- Setting
         console.log('Afterset: '+ component.get("v.Cname"));  ---- Undefined

Regards,
VSK98
 
Arun pattnaik 17Arun pattnaik 17
Hi,
you can try the following way to get the parameter list in the method description (child method) .

 var params = event.getParam('arguments');
        if (params) {
            var Cname= params.Cname;
            var city= params.city;
}

To call the method use aura id to find the child component and call the respective method with mentioned parameters as per the defination

 var CDT = component.find("childcomponentName");           
            CDT.myMethod(Cname,city,Assetcnt,CustomerId,children);
Arun pattnaik 17Arun pattnaik 17
Try calling the method in your component in some button click.
component.myMethod(Cname,city,Assetcnt,CustomerId,children)
VSK98VSK98
Hi Arun,

I can get the values to Child component from Parent Component. But unable to set the value into another attribute,
Component.set("v.Cname",param.Cname) ---- not working
Regards,
VSK98
Raj VakatiRaj Vakati
Refer this link

https://rajvakati.com/2018/01/02/salesforce-aura-method/