LWC Component of timesheet entry and return sold to and ship to value and add in lookup field using NavigationMixin
JS File
import { LightningElement, api, wire } from 'lwc';
import getTimeSheetDetails from '@salesforce/apex/TimeSheetEntryNewBTNOverrideController.getTimeSheetDetails';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { NavigationMixin } from 'lightning/navigation';
export default class NewTimeSheetEntryOverride extends NavigationMixin(LightningElement) {
@api parentRecordId;
@api recordId;
@wire(getTimeSheetDetails, { recordId: '$recordId'})
timeSheetRecord;
navigateToNewTimeSheetEntry() {
console.log('Enter'+this.recordId);
console.log('timeSheetRecord',this.timeSheetRecord);
console.log('this.timeSheetRecord.Id'+this.timeSheetRecord.data.Id);
//console.log('timeSheetRecord'+timeSheetRecord);
const defaultValues = encodeDefaultFieldValues({
TimeSheetId:this.timeSheetRecord.data.Id,
Sold_To__c: this.timeSheetRecord.data.Sold_To__c,
Ship_To__c:this.timeSheetRecord.data.Ship_To__c
});
console.log('defaultValues'+JSON.stringify(defaultValues));
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'TimeSheetEntry',
actionName: 'new'
},
state: {
defaultFieldValues: defaultValues
}
});
}
}
-----------------------------------------------------------------------------
HTML File
<template>
<lightning-card variant="Narrow" title="Time Sheet Entry" icon-name="custom:custom11">
<lightning-button variant="brand" label="New"
title="Create New TimeSheet" onclick={navigateToNewTimeSheetEntry} slot="actions">
</lightning-button>
</lightning-card>
</template>
-----------------------------------------------------------------------------
XML File
<?xml version="1.0"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__Tab</target>
<target>lightning__Inbox</target>
<target>lightning__UtilityBar</target>
<target>lightning__FlowScreen</target>
<target>lightningSnapin__ChatMessage</target>
<target>lightningSnapin__Minimized</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
<target>lightning__RecordAction</target>
</targets>
</LightningComponentBundle>
-----------------------------------------------------------------------------
Controller
public class TimeSheetEntryNewBTNOverrideController {
@AuraEnabled(cacheable=true)
public static TimeSheet getTimeSheetDetails(String recordId){
TimeSheet timeSheetObj=[Select Id,Sold_To__c,Ship_To__c From TimeSheet Where Id =:recordId];
System.debug('timeSheetObj'+timeSheetObj);
return timeSheetObj;
}
}
Comments
Post a Comment