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
Ananthanarayanan NemmaraAnanthanarayanan Nemmara 

Date not auto-populating

Hi All,

I am trying to auto-populate the date feild in a lightning component which seemed to be working fine few days before but now its not working. Don't know is it because of any release.

Please find below the code:

component:
<aura:component controller="customLookupController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
    
    
    <aura:attribute name="fromSalesperson" type="sObject" default=""/>
    <aura:attribute name="toSalesperson" type="sObject" default=""/>
    <aura:attribute name="searchResult" type="List" default="{}"/>
    <aura:attribute name="request" type="date"/>
    <aura:attribute name="effective" type="date" />
    
    <aura:handler name="init" action="{!c.init}"  value="{!this}" />
  
 
    <table>
        <tr>
            <td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.fromSalesperson}" label="From Salesperson" /></td>
              <td style="padding:15px"><c:customLookup objectAPIName="user" IconName="standard:user" selectedRecord="{!v.toSalesperson}" label="To Salesperson"   /></td> 
        </tr>
        <tr>
            <td style="padding:15px"><lightning:input aura:id="effectiveDate" value="{!v.effective}" name="effectiveDateOfChange" type="date" label="Effective Date of Change" required="true"/></td>
            <td style="padding:15px"><lightning:input aura:id="requestDate" value="{!v.request}" name="dateRequested" type="date" label="Date Requested" required="true" class="slds-hidden" /></td>
            
        </tr>

controller:
{
    init : function(component,event,helper) {
    var today = new Date();
    var monthDigit = today.getMonth() + 1;
    if (monthDigit <= 9) {
        monthDigit = '0' + monthDigit;
    }
    component.set('v.request', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());
    component.set('v.effective', today.getFullYear() + "-" + monthDigit + "-" + today.getDate());     
},

The date was auto-populating last week.
User-added image
Can someone please help me with this.

Regards,
Anand
 
Best Answer chosen by Ananthanarayanan Nemmara
Ananthanarayanan NemmaraAnanthanarayanan Nemmara
Hi All,

I have resolved this issue. Added the below code:
     init : function(component, event, helper) {
    var today = new Date();
    var monthDigit = today.getMonth()+1;
    var daydate= today.getDate();
    if(daydate<=9)
    {
         daydate = '0' + daydate;
    }
    if (monthDigit <= 9) {
        monthDigit = '0' + monthDigit;
    }
    var finaldate = today.getFullYear() + "-" + monthDigit + "-" + daydate;
    
    component.set("v.request", finaldate);
    component.set("v.effective", finaldate); 

Regards,
Anand

All Answers

Ananthanarayanan NemmaraAnanthanarayanan Nemmara
And the funniest part is its still updating the date in the backend and just not showing up in the view
Ananthanarayanan NemmaraAnanthanarayanan Nemmara
Hi All,

I have resolved this issue. Added the below code:
     init : function(component, event, helper) {
    var today = new Date();
    var monthDigit = today.getMonth()+1;
    var daydate= today.getDate();
    if(daydate<=9)
    {
         daydate = '0' + daydate;
    }
    if (monthDigit <= 9) {
        monthDigit = '0' + monthDigit;
    }
    var finaldate = today.getFullYear() + "-" + monthDigit + "-" + daydate;
    
    component.set("v.request", finaldate);
    component.set("v.effective", finaldate); 

Regards,
Anand
This was selected as the best answer