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
Sundar rajan ASundar rajan A 

How to Access the fieldvalue in Helper function from the controller returned List Variable in Lightning Component

Hi Friends,
My requirement is disable the Quick action button after 14 days from the record creation date.There is no option to disable to Lightning quick option button,so i plan to show a popup window i calculated the days between created Date and today date and stored in the wrapper list variable . My problem is I not able  to access the field value in helper from the controller returned List variable. I am new to Lightning .

My component :

<aura:component controller="SelectBuyersController" implements="force:hasRecordId,force:lightningQuickActionWithoutHeader">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="people" type="Object[]" />
    <aura:attribute name="selPerson" type="Object" />
    <aura:attribute name="days" type="Decimal" />
    <aura:handler name="change" value="{!v.selPerson}" action="{!c.newPerson}" />
    <aura:attribute name="errorMsg" type="String" />
    <aura:attribute name="alertMsg" type="String" />
    <aura:attribute name="remdays" type="Decimal" />
    <aura:attribute name="orderlist" type="List" />
    <aura:attribute name="includeSender" type="Boolean" default="false" />
    
    <div aura:id="alertmsgform" class="hide" style="font-weight:bold;color:red">
        {!v.alertMsg}
        </div>
    <div aura:id="recordviewform" class="hide">
    <div class="container">
        <header class="slds-modal__header">
            <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Add Tag On Buyers </h2>
        </header>
        <div style="font-weight:bold;color:red">{!v.errorMsg}</div>
        <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
            <h3>Buyers</h3>
</div>
</div>
</div>


My Lightning Controller:

({
    // Initializing function
    doInit : function(cmp, event, helper) 
    {
    
        helper.getCurrentTagOnBuyers(cmp);
       
    },


My Lightning Helper:

({
    
    getCurrentTagOnBuyers : function(cmp) 
    {
        var recordId = cmp.get("v.recordId");
        
        var action = cmp.get("c.getTagOnBuyers");
        action.setParams({ orderTrackerId : recordId});
        
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set('v.wraperlist', response.getReturnValue());
                var recordviewform = cmp.find('recordviewform');
                var alertmsgform = cmp.find('alertmsgform');
                cmp.set("v.alertMsg", "TagOn Buyer Only added within 14 days.");
                
                
               
                 if(!res.RemainingDays  < 14)
                {
                    alert('Less days');
                    
                    $A.util.addClass(alertmsgform, 'hide');
                  $A.util.removeClass(recordviewform, 'hide');
                    
                    
                }
               else if(!res.RemainingDays > 14)
                {
                 alert('More days');
                    $A.util.removeClass(alertmsgform, 'hide');
                    $A.util.addClass(recordviewform, 'hide');
                    
                }
});
        
        $A.enqueueAction(action);
        
    },





My Apex controller:
public class SelectBuyersController{

    
    public class CustomResponse
    {
        @AuraEnabled
        public String id = NULL;
        @AuraEnabled
        public String name = NULL;
        @AuraEnabled
        public Decimal RemainingDays ;
        
        
        public CustomResponse(String id, String name, Decimal RemainingDays )
        {
            this.id = id;
            this.name = name;
            this.RemainingDays = RemainingDays;
        }
    }
    
   
    @AuraEnabled
    public static List<CustomResponse> getTagOnBuyers(Id orderTrackerId)
    {
    Decimal days;
   
     Decimal RemainingDays ;
        List<Order_TagOn_Buyer__c> TagOnOrderbuyer= 
            [SELECT Internal_Contact__r.Id, 
                    Internal_Contact__r.Name,Order_Tracker__r.DaysFromCreatedDate__c 
                    FROM Order_TagOn_Buyer__c
             WHERE Order_Tracker__c = :orderTrackerId];
             
        System.debug('Order buyer'+TagOnOrderbuyer);
        
        List<CustomResponse> people = new List<CustomResponse>();
        
        
        List<Order_Tracker__c> OrderTrackerLst= 
            [SELECT Id,name,OwnerId,S_Number__c,Cancel_Date__c,Buyer_Account__c,Buyer_Account__r.name,
             Walkthrough_Expected_Date__c, Walkthrough_Required__c,CreatedDate
             FROM Order_Tracker__c 
             WHERE Id = :orderTrackerId];
        for(Order_Tracker__c OT : OrderTrackerLst )
        {
        Date dueDate = System.today();
    Integer daysBetween = date.valueof(OT.CreatedDate).daysBetween(dueDate);
    System.debug('Days Between'+daysBetween);
    if(daysBetween <= 14)
    {
    RemainingDays = 14 - daysBetween ;
    
    }
    else
    {
    RemainingDays = daysBetween - 14 ;
    
    }
    System.debug('RemainingDays '+RemainingDays);
        }
        
        for(Order_TagOn_Buyer__c TagOnBuyer: TagOnOrderbuyer)
        {
            CustomResponse person = NULL;
           days =  TagOnBuyer.Order_Tracker__r.DaysFromCreatedDate__c;
            if(TagOnBuyer.Internal_Contact__r.Id != NULL)
            {
                person = 
                    new CustomResponse(TagOnBuyer.Internal_Contact__r.Id,
                                       TagOnBuyer.Internal_Contact__r.Name , RemainingDays );
            }
           /* else
            {
                person = 
                    new CustomResponse(stakeholder.Internal_User__r.Id,
                                       stakeholder.Internal_User__r.Name);
            } */
            
            people.add(person);
        }
        
        return people;
       
    }
    
 
MagulanDuraipandianMagulanDuraipandian
Hi,
Store the returned value in the controller. Access the stored value in the helper.
--
Magulan Duraipandian
www.infallibletechie.com
Sundar rajan ASundar rajan A
Hi Magulan,
Thank you for  quick response.

My question is how to get the particular field value from the response from setcallback function.

 action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set('v.wraperlist', response.getReturnValue());
                var recordviewform = cmp.find('recordviewform');
                var alertmsgform = cmp.find('alertmsgform');
                cmp.set("v.alertMsg", "TagOn Buyer Only added within 14 days.");
                
                
               
                 if(!res.RemainingDays  < 14)
                {
                    alert('Less days');
                    
                    $A.util.addClass(alertmsgform, 'hide');
                  $A.util.removeClass(recordviewform, 'hide');
                    
                    
                }

I need to check if condition like above , Is this correct ? setcallback method is return the wrapper list variable from the apex controller. wrapper list is has the  Remainingdays variable values , how to access or get  this Remainingdays variable in helper class.