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
AnshiiAnshii 

lwc help1

Hi every one,using lwc i am able to navigate to the detailpage but unable to open the new form when i click on new booking  getting errors in js file,please help me out.

Thanks in Advance.

html:
-----------

<template>
<!-- <lightning-card title="All Bookings">
<div class="slds-p-around_medium">
<template if:true={contacts} for:each={contacts} for:item="contact">
<li key={contact.Id}>
<a>{contact.Name}</a>
</li>
</template>
</div>
</lightning-card>-->
<lightning-card title="title of the component" class="slds-clearfix">
<div class="slds-p-around_medium">
<div class="slds-float_left"> <template if:true={bookings} for:each={bookings} for:item="booking">
<li key={booking.Id}>
<a target="_blank" onclick={handleOnClick} data-target-id={booking.Id}>{booking.Name}</a>
</li>
</template>
</div>
</div>
<div class="slds-clearfix">
<div class="slds-float_right">
<lightning-button label="New Booking" class="slds-m-left_x-small" onclick={navigatetorecordpage}></lightning-button>
</div>
</div>
</lightning-card>
</template>
-------
js:
import { LightningElement,api,track,wire } from 'lwc';
import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 

   export default class lwcTask extends NavigationMixin (LightningElement) {  
    bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


let _recordId=event.target.dataset.targetId;

navigatetorecordpage( ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: 'New',
}
});
}
}
   }


 
ravi soniravi soni
hi ,
I changed in js file  use below js and check still you are getting any error or it has resolved.
import { LightningElement,api,track,wire } from 'lwc';



import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 
let _recordId = '';
   export default class lwcTask extends NavigationMixin (LightningElement) {  
bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


_recordId=event.target.dataset.targetId;
}

navigatetorecordpage( ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: 'New',
}
});
}

   }
if it helpfull to you, mark it as best answer.
Thank you
 
AnshiiAnshii
Hi,thanks for your reply ,errors gone but functionality has broken doesnot navigating and not able to open the form
ravi soniravi soni
hi Anshii,
try below code. I believe it will work as expected.
import { LightningElement,api,track,wire } from 'lwc';

import getBookingList from '@salesforce/apex/taskexample.getBookingList';
 
import {NavigationMixin} from 'lightning/navigation';
 let _recordId = '';

   export default class lwcTask extends NavigationMixin (LightningElement) {  
bookings;
error;


@wire(getBookingList) bookingDetails({error,data}){
if(data){
this.bookings=data;
}
else if(error){
this.error=error;
}
}


handleOnClick(event){
event.preventDefault();


 _recordId=event.target.dataset.targetId;
this.navigateToPage('view');
}

navigatetorecordpage( ){
_recordId = '';
this.navigateToPage('New');
}





navigateToPage(sActionName) {
        // View a custom object record.
		
		this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: _recordId,
objectApiName: 'Bokking__c',
actionName: sActionName,
}
});
    }

   }

thanks