I have a multi-select picklist field that I need to transform to an array of number to use in a API. How can I do this in a Flow?

Context: I need to send the result of a multi-select picklist to an external company through an API. For that I created a flow:

  • In a Screen Flow I configured a Screen Input Component with a multi-select picklist and other mandatory fields
  • I configured an assignment to assign those fields to the API fields --> here I cannot assign the multi-select picklist to the appropriate field because the data type must be an "array" of number
  • I configured an Action for the API

Current Blocker: I do not know how to transform the multi-select picklist to an array type: [1, 2]. I know how to transform a string to a number (with a formula), but not how to transform to an array type.




1 Answer 1


This is a hard problem for Flow to do directly so you'll need to escape to Apex via an Apex Action. Fortunately, the good folks at UnofficialSF.com have one already built that you can install


One of the options is to return a collection of strings for each element in the MSP

  • Input is the record + name of MSP field + action
  • Output depends on action, but in your case, a collection of strings for each selected MSP value for that record.

Once you get back a collection of strings, you can loop through that collection in Flow and use formula expressions to turn into a collection of numbers


Based on the new information in the OP, you should do the following (assuming you have no Apex skills):

  1. Starting with the MSP value taken from the screen element ..
  2. Use an ApexAction to invoke the MultiSelectMagic invocable apex. Use the return type of collection of strings. Save this in a Flow variable called selectedMspValues
  3. Create a Flow variable of type Text. Call it jsonArray Initialize it to [.
  4. Using a Flow loop, go through each item in selectedMspValues. Within the loop, use an Assignment element to append to jsonArray the number equivalent of the string MSP value + a comma ,
  5. At the end of the loop, append a final ']' using another assignment and formula expression.
  6. Lastly, you'll need to use SUBSTITUTE to replace ,] with ]


  • MSP is 4;6;9
  • MagicMover returns this as a collection variable of three strings: 4, 6, and 9
  • You start with a result variable [
  • As you loop, the result variable goes to [4,, then [4,6,, then [4,6,9,
  • At then end of the loop, you add the final ']' and have [4,6,9,]
  • And then cleanup to yield a text variable [4,6,9] ready for your outbound callout

Now in apex, this is way simpler

  • Hi, thanks for the answer. Would it be possible to input a field from the flow screen component with this? Thanks Commented Jun 17, 2022 at 11:31
  • if you construct a record variable from screen input, then yes
    – cropredy
    Commented Jun 17, 2022 at 15:34
  • How can I do that? Commented Jun 27, 2022 at 18:58
  • Please edit your original question with more details about what you want to do.
    – cropredy
    Commented Jun 28, 2022 at 4:22
  • Hi, I edited the question. Hope this is clearer? Commented Jun 29, 2022 at 7:58

You must log in to answer this question.

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