Add new string to a list with custom function

Add new string to a list with custom function

Hi friends,

I'm trying to insert data from a Zoho CRM text field into a multi-select field also in Zoho CRM using Zoho Flow.

After spending a couple hours trying to build a proper function with no success, I'm here to ask for some help. :)

Basically, I need to get a text from the field A (text type) and add it the field B, however, B is a multi-select field type and the text from A should be added to B while keeping the previous data.

Example:
1. Field A has the string "soccer"
2. Field B has the list "john", "mary", "peter"

The expected result is:
3. Now Field B has the data: "soccer", "john", "mary", "peter"

Could you help me to fix this custom function to use it in Zoho Flow?

Thank you!

More information below:

The actual script is only returning "soccer", disregarding all source values from the multi-select field (B).


Custom function script: https://zwdrive.com/juGb57
Custom function input: https://zwdrive.com/sj2jzO
Custom function output: https://zwdrive.com/b9RIIA
Custom function script below:
  1. list addToList(list TopicsList, string newTopic)
    {
    if(newTopic == null)
    {
        return list();
    }
    TopicsList = input.newTopic.tolist(";");
    return TopicsList;
    }