1

Can anyone help me with how I get the specific object's All Recordtype Names in Lwc.
I'm using the wire "getObjectInfo" method to get all info for object but I'm not getting how I iterate over "recordtypeinfo"(getting it from getObjectInfo method).
"recordTypeInfos": {
            "recordTypeId 1": {
                "available": true,
                "defaultRecordTypeMapping": false,
                "master": true,
                "name": "Master",
                "recordTypeId": "recordTypeId 1"
            },
            "recordTypeId 2": {
                "available": true,
                "defaultRecordTypeMapping": true,
                "master": false,
                "name": "XYZ",
                "recordTypeId": "recordTypeId 2"
            }
}

I'm getting above object from "data.recordTypeInfos".
Can someone help me to push name and id to one array.
ex.

arr.push({ label : "RecordTypeName HERE" , value: "RecordTypeId Here" });

1 Answer 1

2

In general, you want to use Array.prototype.map to convert an Array from one type to another.

let arr = Object.values(data.recordTypeInfos).map(
  ({ name: label, recordTypeId: value }) => ({
    label,
    value,
  })
);

Where Object.values pulls out all the values in an object so you can work with them as an array, () => ({}) is an arrow function that creates an object literal, {name:label,recordTypeId:value} is a destructuring statement that assigns name to label, and recordTypeId to value, and { label, value } takes the parameters with those names and creates a new object. Array.prototype.map itself creates a copy of the original Array, transforming it through the function provided as the first parameter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .