I have a picklist for users to choose which version of our product customers have.
I have a second picklist for users to choose which version of our product to “upgrade to”. Included in the upgrade, are manual, but required, patches (or hotfixes) that must be applied.
The Operations team is requesting that I build a field “Upgrade to Hotfix Version” that shows all of the user requested patches (hotfixes), as well as any required ones. This needs be automated as we have over 20 versions of software that require specific patches.
This was a case for Apex to update the field. However, as of Spring ’19 release of Salesforce Lightning Flow, I can accomplish this with Lightning Flow! Why? Flow lets me assign variables, re-use them, and append them, as if I was coding. But I’m clicking.
I have 9 values to deal with for patching. Each release can have up to 9 patches in my business. Thus, the scope of the string is 9 individual values. So I need to make 9 switches. (I like to think of switches like light switches. On or Off). In this way, all switches are off (default = FALSE) at the beginning.
- Record the user input (ie “3”)
- Add required patches (“1,2”)
- Build a new string with both user input and requirements. (“1,2,3”)
Whatever you choose to do, remember that you need a before and after variable, something to store the string as you got it, and a new string for the output.
Process: Steps are from the image above.
Step 1: Get a string you can work with. You need to get the string (text) value of the multi select picklists. Salesforce always semi-colon delimits this field.
Step 2: Use some logic to ask “does the string contain “x” (text) value. Use the “contains” logic. For each result that is true, you need a Boolean Variable to track the result. Like a light switch, turn them on. In my case, I have 9 switches, to accommodate the 9 possible patches.
Step 3: After you have all the required user input tracked, now I need to check for several options that are required (6 of them for my use case).
Step 4: For each, just turn the light switch on where appropriate. (At this point, you are just running logic. ) Basically, If my customer is upgrading to a specific version, then I require patch 2 for example, I turn on the “Light Switch” for patch 2.
Step 5: Now that we are done turning on switches, we need to put the switches back together into a semi-colon delimited string variable. (Similar to step1). Go through each switch, and if the switch is ON, (boolean = TRUE), then “add” a specific value (which must exist in the Multi Select Picklist) with a semicolon in front of it, using the “Add” logic. This will append a string variable until you have a completed string. In the screenshot, you can see the two arrows indicating how I used “Add” in the assignment.
Step 6: After using the Boolean switches to build a string, Assign the string to the Variable you are using to update the record.
Step 7: Run an UPDATE on the record to save the record.
Step 8 and beyond: You need to GET the record again to now see what the value of the field is that we just updated. (I suppose you could use the variable, but best practice is to query the record after the update has complete. ) I use this last “GET” to post to Chatter.
I used all numbers in this example, but because the numbers are represented as text, once you learn this, you will be able to manipulate any Multi Select Picklist by taking is apart into it’s text only constituents, applying needed updates, and building a new properly formatted, semi-colon delimited string, that you can insert into any Multi-Select Picklist.
Enjoy — Troy