1

I am having this error while running lightning component from preview. Locker service has been enabled recently.

enter image description here

below are the codes,

component

<aura:component controller="ReportController">
    <!-- Load external scripts/styles -->
    <ltng:require styles="/resource/slds080/assets/styles/salesforce-lightning-design-system.css" />
    <!--<ltng:require scripts="/resource/mf_util" afterScriptsLoaded="{!c.doInit}"/>-->

    <!-- Register event handlers -->
    <aura:registerEvent name="componentException" type="c:componentException"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"></aura:handler>

    <!-- External attributes -->
    <aura:attribute name="titleLabel" type="String" description="External. API name of the Custom Label containing the chart's title text."></aura:attribute>
    <aura:attribute name="decimalPlaces" type="Integer" default="0" description="External. Number of decimal places to show. Trailing 0's will only be shown for currency values."></aura:attribute>
    <aura:attribute name="queries" type="Object[]" description="External. Array of objects representing SOQL queries used to grab data."></aura:attribute>
    <aura:attribute name="monthsToShow" type="Integer" default="7"></aura:attribute>

    <!-- Internal attributes -->
    <aura:attribute name="results" type="Object[]" description="Internal. Array of results from executing the SOQL queries in 'queries.'"></aura:attribute>
    <aura:attribute name="title" type="String" description="Internal. The value of the Custom Label defined in 'titleLabel.'"></aura:attribute>
    <aura:attribute name="intervalId" type="String" description="Internal. The ID of the interval used to periodically check if the dynamically accessed labels are loaded."></aura:attribute>
    <aura:attribute name="detailHeaders" type="String[]" description="Internal. Array of headers for the table."></aura:attribute>
    <aura:attribute name="detailRows" type="Object[]" description="Internal. Array of rows containing values for the table."></aura:attribute>
    <aura:attribute name="cseFilter" type="String[]"></aura:attribute>
    <aura:attribute name="idnFilter" type="String[]"></aura:attribute>
    <aura:attribute name="accountFilter" type="String[]"></aura:attribute>
    <aura:attribute name="isLocal" type="Boolean" default="false" description="Internal. Indicates whether the query fields have a Local__c in them."></aura:attribute>
    <aura:attribute name="divisionMap" type="Object" description="Internal. Object containing the table row results of all the data and calculations by BU and division."></aura:attribute>

    <div class="loading-wrap">
        <div aura:id="spinner" class="loading slds-hide">
            <img class="slds-spinner--large" src="/resource/slds080/assets/images/spinners/slds_spinner_brand.gif" alt="Loading..." />
        </div>
        <br/><br/><br/>
        <div class="slds-text-align--center">
        <div class="slds-text-heading--small">Trends by Product Line</div>
        </div>        
       <c:SelectorCSE isLocal="true" filterChanged="c.filterChanged"/>
        <div class="slds-grid slds-wrap">
            <div class="slds-col slds-size--1-of-1 slds-medium-size--1-of-2 slds-p-around--small">
                <div class="slds-form-element">
                    <label class="slds-form-element__label">{!$Label.c.MF_Wakeup_SelectFieldv2}</label>
                    <div class="slds-form-element__control">
                        <ui:inputSelect aura:id="selectField" change="{!c.fieldChanged}">
                            <ui:inputSelectOption text="sales" label="{!$Label.c.MF_Wakeup_OptionRevenue}"></ui:inputSelectOption>
                            <ui:inputSelectOption text="units" label="{!$Label.c.MF_Wakeup_OptionUnits}"></ui:inputSelectOption>
                            <ui:inputSelectOption text="asp" label="{!$Label.c.MF_Wakeup_OptionASP}"></ui:inputSelectOption>
                        </ui:inputSelect>
                    </div>
                </div>
            </div>
            <div class="slds-col slds-size--1-of-1 slds-medium-size--1-of-2 slds-p-around--small">
                <div class="slds-form-element">
                    <label class="slds-form-element__label">{!$Label.c.MF_Wakeup_SelectPeriod}</label>
                    <div class="slds-form-element__control">
                        <ui:inputSelect aura:id="selectPeriod" change="{!c.periodChanged}">
                            <ui:inputSelectOption text="months" label="{!$Label.c.MF_Wakeup_OptionMonths}"></ui:inputSelectOption>
                            <ui:inputSelectOption text="quarters" label="{!$Label.c.MF_Wakeup_OptionQuarters}"></ui:inputSelectOption>
                        </ui:inputSelect>
                    </div>
                </div>
            </div>
        </div>
        <c:DataTable title="Trends by Product Line" shrinkTitle="true" headers="{!v.detailHeaders}" rows="{!v.detailRows}" responseMode="stack"></c:DataTable>
        <br/><br/><br/>
    </div>
</aura:component>

controller :

({ 

    doInit : function(component, event, helper) {
        window.alert('entry into init');
        var titleLabel = component.get('v.titleLabel');
        console.log(titleLabel + ' Init');

        var intervalId = window.setInterval(function(cmp, a) {
            console.log('terr table label check');
            //keep trying to load label every half second
            var labelA = $A.get('$Label.c.' + a);
            //check if labels are all loaded
            if(labelA !== '[c.' + a + ']' && labelA.length) {
                cmp.set('v.title', labelA);
                window.clearInterval(cmp.get('v.intervalId'));
            }
        }, 1000, component, titleLabel);
        component.set('v.intervalId', intervalId);

        var i, j, isLocal = false;
        var queries = component.get('v.queries');
        for(i = 0; i < queries.length; i++) {
            for(j = 0; j < queries[i].fields.length; j++) {
                if(queries[i].fields[j].indexOf('Local__c') > 0) {
                    isLocal = true;
                    break;
                }
            }
        }
        component.set('v.isLocal', isLocal);
        window.alert('exit before helper');
        helper.getQueryResults(component);
        window.alert('exit after helper');
    },
    filterChanged : function(component, event, helper) {
        helper.applyFilters(component, event);
    },
    fieldChanged : function(component, event, helper) {
        helper.buildTable(component);
    },
    periodChanged : function(component, event, helper) {
        var queries = component.get('v.queries');
        var selected = component.find('selectPeriod').get('v.value');
        console.log('selected: ' + selected);

        var i, j;
        //only need to change the second query (months)
        if(selected === 'months') {
            //2nd query contains the months
            if(queries.length && queries.length > 1) {
                console.log('change to months');
                for(i = 0; i < queries[1].fields.length; i++) {
                    queries[1].fields[i] = queries[1].fields[i].replace('FISCAL_QUARTER', 'CALENDAR_MONTH');
                }

                for(i = 0; i < queries[1].filters.length; i++) {
                    queries[1].filters[i] = queries[1].filters[i].replace('LAST_N_FISCAL_QUARTERS', 'LAST_N_MONTHS').replace('THIS_FISCAL_QUARTER', 'THIS_MONTH');
                }
            }
        }
        else if(selected === 'quarters') {
            console.log('change to quarters');
            for(i = 0; i < queries[1].fields.length; i++) {
                queries[1].fields[i] = queries[1].fields[i].replace('CALENDAR_MONTH', 'FISCAL_QUARTER');
            }

            for(i = 0; i < queries[1].filters.length; i++) {
                queries[1].filters[i] = queries[1].filters[i].replace('LAST_N_MONTHS', 'LAST_N_FISCAL_QUARTERS').replace('THIS_MONTH', 'THIS_FISCAL_QUARTER');
            }
        }

        console.log('changed queries:');
        console.log(queries);

        component.set('v.queries', queries);
        helper.getQueryResults(component);
    }
})
3

I can see error at below line,

window.setInterval(function(cmp, a) 

It should be,

window.setInterval(function(component, a) 
  • Not sure the var name matters in this case as the calling js is simply passing the values in. – Eric May 15 '17 at 12:30

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.