+ Start a Discussion
The new LearnerThe new Learner 

how to create a record on selection of record type in lwc

Hi Experts,
 
I need to create a record on the selection of record type,  I have created a Combobox and populated the record type, now my requirement is that on the selection of that record type I need to create a record.
 
<template>
    <div if:true={objectInfo.data}>
        <lightning-combobox name="recordType" label="Record Type" placeholder="Choose Status"
        value={value} 
        options={recordTypeId1}>
        </lightning-combobox>
        </div> 
</template>

jS:
import { LightningElement, track, wire, api } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import CONTACT_OBJECT from '@salesforce/schema/Support_Request__c';

export default class CreateContact extends LightningElement {

    @track statusOptions;
    @track value;
    @api objectApiName;

    @track objectInfo;

    @wire(getObjectInfo, { objectApiName: CONTACT_OBJECT,})
    objectInfo;


    get recordTypeId1() {
        var recordtypeinfo = this.objectInfo.data.recordTypeInfos;
        var uiCombobox = [];
        console.log("recordtype" + recordtypeinfo);
        for(var eachRecordtype in  recordtypeinfo)//this is to match structure of lightning combo box
        {
          if(recordtypeinfo.hasOwnProperty(eachRecordtype))
          uiCombobox.push({ label: recordtypeinfo[eachRecordtype].name, value: recordtypeinfo[eachRecordtype].name })
        }
        console.log('uiCombobox' + JSON.stringify(uiCombobox));
      return uiCombobox;
    }

}
Meta:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
     <target>lightning__AppPage</target>
     <target>lightning__RecordPage</target>
     <target>lightning__HomePage</target>
 </targets>
  
</LightningComponentBundle>