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
ArunaAruna 

In screen flow dynamically get the picklist values and created data table with each pick value as row with input text value

Hi,
I don't know if this is possible. I would appreciate any help. 

The requirement is to dynamically get picklist values and loop through each to display the pick value in each row's screen flow data table with an input text field. Once the data is entered, save the picklist value and input text in another object.

screen flow data example as below
User-added image
Ramesh DRamesh D
Hi @aruna,

To dynamically retrieve picklist values and create a data table with each pick value as a row and an input text value, you have to create a custom lwc component to do that follow these steps:
  1. Query the picklist values from the object metadata using the Salesforce Object Describe API. You can use the wire service to retrieve the picklist values for the desired field.
  2. Store the picklist values in an array or list.
  3. Create a data table with the required columns. The first column should contain the picklist values retrieved in step 1, and the second column should contain an input text field for the user to enter data.
  4. Use a loop to iterate over the picklist values and add a row to the data table for each picklist value. In each row, add the picklist value in the first column and an input text field in the second column.

Here is some sample code to get you started:
  1. Define the Apex method to retrieve picklist values from object metadata:
@AuraEnabled(cacheable=true)
public static List<String> getPicklistValues(String objectName, String fieldName) {
    List<String> picklistValues = new List<String>();
    try {
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Schema.SObjectType objType = schemaMap.get(objectName);
        if (objType != null) {
            Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
            if (objDescribe.fields.getMap().containsKey(fieldName)) {
                Schema.DescribeFieldResult fieldDescribe = objDescribe.fields.getMap().get(fieldName).getDescribe();
                if (fieldDescribe != null && fieldDescribe.isPicklist()) {
                    List<Schema.PicklistEntry> picklistValuesList = fieldDescribe.getPicklistValues();
                    for (Schema.PicklistEntry picklistEntry : picklistValuesList) {
                        picklistValues.add(picklistEntry.getLabel());
                    }
                }
            }
        }
    } catch (Exception e) {
        System.debug('Exception: ' + e.getMessage());
    }
    return picklistValues;
}
2. In your LWC, import the Apex method and define a wired property to retrieve the picklist values:
import { LightningElement, wire } from 'lwc';
import getPicklistValues from '@salesforce/apex/ObjectNameController.getPicklistValues';

export default class MyComponent extends LightningElement {
    picklistValues = [];

    @wire(getPicklistValues, { objectName: 'MyObject', fieldName: 'MyPicklistField' })
    wiredPicklistValues({ error, data }) {
        if (data) {
            this.picklistValues = data;
            this.createTableRows();
        } else if (error) {
            console.error(error);
        }
    }

    createTableRows() {
        // Create data table rows using picklistValues
    }
}
3. HTML 
<template>
    <lightning-datatable
        key-field="id"
        data={tableData}
        columns={columns}
        hide-checkbox-column>
    </lightning-datatable>
</template>

Let me know if you need more info​​​​​​​