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
Phuc Nguyen 18Phuc Nguyen 18 

Get and Pass Record Type from Aura component to LWC

I am overriding a new button on a custom object with an  aura component(LWC wrapped inside Aura).  How do I get the record Type  that the user has selected and pass it to the LWC?  The reason I need this is that the picklist values are based on the record type.
 
Thanks
P
Best Answer chosen by Phuc Nguyen 18
Santosh Kumar 348Santosh Kumar 348
Hi Phuc,

Your question has 2 parts first is how you will get the recordtype id in aura component which you have used to override the button.
And then you want to pass that value to LWC component.

So for first step you need to use "lightning:hasPageReference" in your component. This will help you to get/access to the pageReference attribute.
This will help you to get the recordtypeId. Refer below link:

https://www.biswajeetsamal.com/blog/get-selected-record-type-id-in-standard-button-overrides-lightning-component/

Next is to pass this value to LWC you need to have a variable with @api annotated in LWC for example, where you can set the value from aura compoenent :
 
import { LightningElement, api } from "lwc";

export default class LightningCardInLwc extends LightningElement {
  @api recTypeId;
}


You can use below syntax to pass the value, where "recTypeId" is a variable in LWC and "selectedRecordId" is an attribute in AURA.
<aura:component implements="force:hasRecordId,lightning:actionOverride,lightning:hasPageReference">
    <aura:attribute name="selectedRecordId" type="Id" />
    <c:LWCComponent recTypeId={!v.selectedRecordId}/>
</aura:component>



If it helped then can you please mark it as the best answer so that it can be used by others in the future.

Regards,
Santosh Kumar

All Answers

Santosh Kumar 348Santosh Kumar 348
Hi Phuc,

Your question has 2 parts first is how you will get the recordtype id in aura component which you have used to override the button.
And then you want to pass that value to LWC component.

So for first step you need to use "lightning:hasPageReference" in your component. This will help you to get/access to the pageReference attribute.
This will help you to get the recordtypeId. Refer below link:

https://www.biswajeetsamal.com/blog/get-selected-record-type-id-in-standard-button-overrides-lightning-component/

Next is to pass this value to LWC you need to have a variable with @api annotated in LWC for example, where you can set the value from aura compoenent :
 
import { LightningElement, api } from "lwc";

export default class LightningCardInLwc extends LightningElement {
  @api recTypeId;
}


You can use below syntax to pass the value, where "recTypeId" is a variable in LWC and "selectedRecordId" is an attribute in AURA.
<aura:component implements="force:hasRecordId,lightning:actionOverride,lightning:hasPageReference">
    <aura:attribute name="selectedRecordId" type="Id" />
    <c:LWCComponent recTypeId={!v.selectedRecordId}/>
</aura:component>



If it helped then can you please mark it as the best answer so that it can be used by others in the future.

Regards,
Santosh Kumar
This was selected as the best answer
Phuc Nguyen 18Phuc Nguyen 18

Thanks for the reply @Santosh.  Do you know how to render teh Record type on a lightning-record-edit-form?  If I hardcode the recordtype and use record-type-id= "01241144444" I see the record type.  But If I use record-type-id={recTypeId} its blank.  Just want to confirm its coming over.  Thanks
P

Santosh Kumar 348Santosh Kumar 348
You can check if you are getting some value in "recTypeId". Using console.log.
Try to print and see if you are getting proper value in "recTypeId".