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
GhanesanGhanesan 

clicking on button, date field should populate as today's date

Hi, 
when button is clicked, the date field should populate as today's date. i am trying in LWC and its doesnt work. please see below code.

HTML:
<template>
   
    <lightning-button
                     class="slds-button slds-button_brand"
                      label="Resignation"
                      variant="brand"
                      onclick={updateDate}>
    </lightning-button>
</template>

JS:

import { LightningElement, api, wire} from 'lwc';
import {getRecord} from 'lightning/uiRecordApi';
import RESIGN_FIELD from '@salesforce/schema/Employee_Information__c.DN_Resignation_Date__c';
const fields = [RESIGN_FIELD];
export default class ResignButton extends LightningElement {
    @api recordId;
    @wire(getRecord, { recordId: '$recordId', fields })
    employee_Information__c;
updateDate(){
    let fields = new Date().toISOString();
}
}
Srikanth DasariSrikanth Dasari
 
import { LightningElement, api, wire} from 'lwc';
import { updateRecord } from 'lightning/uiRecordApi';
import RESIGN_FIELD from '@salesforce/schema/Employee_Information__c.DN_Resignation_Date__c';
import ID_FIELD from '@salesforce/schema/Employee_Information__c.Id';

export default class ResignButton extends LightningElement {
    @api recordId;
    @wire(getRecord, { recordId: '$recordId', fields: [RESIGN_FIELD] })
    employeeInfo;

get resignDate() {
      return getFieldValue(this.employeeInfo.data, RESIGN_FIELD );
}

updateDate(){
    const fields = {};
fields[ID_FIELD.fieldApiName] = this.recordId;
 fields[RESIGN_FIELD .fieldApiName] = new Date();
const recordInput = { fields };
updateRecord(recordInput)
  .then(() => {
    this.dispatchEvent(
    new ShowToastEvent({
    title: 'Success',
    message: 'Employee Information updated',
    variant: 'success'
  })
  );
  })
  .catch(error => {
     this.dispatchEvent(
     new ShowToastEvent({
     title: 'Error creating record',
     message: error.body.message,
    variant: 'error'
  }) );
 });
 }
}