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
JGFJGF 

Flow - Populate Picklist from values splitted from String var

Hello everyone,

I've a situation where a record has a set of values in a text field received from an integration and this values need to be displayed as a Picklist in a Flow Screen. As this values change for each record I can't make a picklist field.

In the event of being able to split this value into a string of values, I can't seem to be able to create e picklist value set from this values, it will always ask me to choose an existing picklist field for an Object.

Is it possible to create a Picklist Choice Set for the Flow where I set the values it should have?

I don't seem to find any other way to represent that field as a Picklist on a Flow.
Best Answer chosen by JGF
JGFJGF
Hello ANUTEJ,

Thank you very much for the answer. I was just doing something similar but with a LIghtning Web Component as I need to use it in a Flow.

Here is what I did.

1º Create a new LWC

For the XML File:
I create two properties that will be available at the Flow. The first one will allow the component to receive the String with the possible values. The Second one will be where the chosen option will be stored when chosing a value at the Picklist.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="urn:metadata.tooling.soap.sforce.com" fqn="checklistPicklist">
    <apiVersion>48.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <property name="valueString" type="String" label="Values" description="The String with the available values for the Picklist"></property>
            <property name="valueChosen" type="String" label="Chosen Value" description="The String with the value selected at the picklist"></property>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
For the JS File:
With connectedCallback() the component is able to load the received value, split the values with the ';' char and insert each obtained value in the array. The HTML File has an onOnchange event at the picklist that will call assignValue(event) to obtain the chosen value and place it at the output variable.
import { LightningElement, api } from 'lwc';

export default class ChecklistPicklist extends LightningElement
{
    @api valueString; // Arrives from the Flow
    @api valueChosen; // Goes to the Flow

    picklistOptionValues = []; // Contains the options for the Picklist

    connectedCallback()
    {
        var arrayValues = this.valueString.split(';');
        for(var i = 0; i < arrayValues.length; i++)
        {
            this.picklistOptionValues.push(arrayValues[i]);
        }
    }

    assignValue(event)
    {
        this.valueChosen = event.target.value;
    }

}

For the HTML File:
I just put the picklist, taking the values from the array that contains the splitted String value from de JS File.
<template>
    <select onchange={assignValue} class="slds-select">
        <template for:each={picklistOptionValues} for:item="next">
            <option class="uiINputSelectOption" key={next} value={next}>{next}</option>
        </template>
    </select>
</template>
Once the LWC is created, at the Flow I only need to add the component to a Screen piece and tell the variables that will be used:
Screen Flow

Hope it helps until we can make this without code.

 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi JGF,

I found a developer thread where in one person implemented a dynamic picklist please find the link below:

>> https://developer.salesforce.com/forums/?id=906F0000000BZxgIAG

I think you would be able to use this for reference to implement your scenario.

In case if this helps please close the thread and also mark this as the best answer so that it can be used by others in the future and alos helps in keeping the community clean.

Regards,
Anutej
JGFJGF
Hello ANUTEJ,

Thank you very much for the answer. I was just doing something similar but with a LIghtning Web Component as I need to use it in a Flow.

Here is what I did.

1º Create a new LWC

For the XML File:
I create two properties that will be available at the Flow. The first one will allow the component to receive the String with the possible values. The Second one will be where the chosen option will be stored when chosing a value at the Picklist.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="urn:metadata.tooling.soap.sforce.com" fqn="checklistPicklist">
    <apiVersion>48.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__FlowScreen</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__FlowScreen">
            <property name="valueString" type="String" label="Values" description="The String with the available values for the Picklist"></property>
            <property name="valueChosen" type="String" label="Chosen Value" description="The String with the value selected at the picklist"></property>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
For the JS File:
With connectedCallback() the component is able to load the received value, split the values with the ';' char and insert each obtained value in the array. The HTML File has an onOnchange event at the picklist that will call assignValue(event) to obtain the chosen value and place it at the output variable.
import { LightningElement, api } from 'lwc';

export default class ChecklistPicklist extends LightningElement
{
    @api valueString; // Arrives from the Flow
    @api valueChosen; // Goes to the Flow

    picklistOptionValues = []; // Contains the options for the Picklist

    connectedCallback()
    {
        var arrayValues = this.valueString.split(';');
        for(var i = 0; i < arrayValues.length; i++)
        {
            this.picklistOptionValues.push(arrayValues[i]);
        }
    }

    assignValue(event)
    {
        this.valueChosen = event.target.value;
    }

}

For the HTML File:
I just put the picklist, taking the values from the array that contains the splitted String value from de JS File.
<template>
    <select onchange={assignValue} class="slds-select">
        <template for:each={picklistOptionValues} for:item="next">
            <option class="uiINputSelectOption" key={next} value={next}>{next}</option>
        </template>
    </select>
</template>
Once the LWC is created, at the Flow I only need to add the component to a Screen piece and tell the variables that will be used:
Screen Flow

Hope it helps until we can make this without code.

 
This was selected as the best answer