You need to sign in to do that
Don't have an account?
Ghanesan
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();
}
}
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();
}
}
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[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'
}) );
});
}
}