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
Brenda Paiva 3Brenda Paiva 3 

How to call a function inside other function?

Hello, everyone. 
I have 2 different functions in my lookup component. The first loads the records (doinit) and another fires an event to pass to the parent component the chosen record Id and label.

1) loadValues : function (component, event) {
        var record = component.get("v.record");
        var subheading = '';
        for(var i=0; i<component.get("v.subHeadingFieldsAPI").length ;i++ ){
            if(record[component.get("v.subHeadingFieldsAPI")[i]]){
                subheading = subheading + record[component.get("v.subHeadingFieldsAPI")[i]] + ' • ';
            }
        }
        
        subheading = subheading.substring(0,subheading.lastIndexOf('•'));
        component.set("v.subHeadingFieldValues", subheading);
        console.log('check')
    },

2) choose : function (component,event) {
        var chooseEvent = component.getEvent("lookupChoose");
        chooseEvent.setParams({
            "recordId" : component.get("v.record").Id,
            "recordLabel":component.get("v.record").Name
        });
        chooseEvent.fire();
        console.log('event fired');
    }

the problem is: I have to make those things happen at the same time. I've tried to fire the event in the first function but it didn't work, so I thought in calling the function "choose" inside the "load Values". Can anyone help me with that?
Devi ChandrikaDevi Chandrika (Salesforce Developers) 
Hi Brenda,

Try this way.
loadValues : function (component, event) {
        var record = component.get("v.record");
        var subheading = '';
        for(var i=0; i<component.get("v.subHeadingFieldsAPI").length ;i++ ){
            if(record[component.get("v.subHeadingFieldsAPI")[i]]){
                subheading = subheading + record[component.get("v.subHeadingFieldsAPI")[i]] + ' • ';
            }
        }
        
        subheading = subheading.substring(0,subheading.lastIndexOf('•'));
        component.set("v.subHeadingFieldValues", subheading);
        console.log('check');
        var action = component.get('c.choose');//added these 2 lines
        $A.enqueueAction(action);
    },
 choose : function (component,event) {
        var chooseEvent = component.getEvent("lookupChoose");
        chooseEvent.setParams({
            "recordId" : component.get("v.record").Id,
            "recordLabel":component.get("v.record").Name
        });
        chooseEvent.fire();
        console.log('event fired');
    }

If this doesn't work write your choose method in helper and call that helper method from loadvalues method like this.
helper.choose();

Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.

Thanks and Regards