Working with MultiSelect Lists

Working with MultiSelect Lists

For this example we use SugarCRM, where MultiSelect fields are supplied as a JSON string, i.e. [{"value1","value2"}

First, I check to make sure my origin value ('reg') and existing value in Sugar ('existing') are not empty, as either case is easy to resolve.

	if (string.IsNullOrEmpty(reg))
		//Starfish.LogMessage("reg is empty");
		result = existing;
	else if (string.IsNullOrEmpty(existing))
		//Starfish.LogMessage("existing is empty");
		result = "[\""+reg+"\"]";

Next, I check to see if the origin value is already selected in the existing Sugar value.

	else if (existing.Contains(reg))
		//Starfish.LogMessage("existing already contains reg");
		result = existing;

Now that all of the easy cases are out of the way, I deal with the case where I need to add the origin value to the existing Sugar value. In order for the data to be consistent for reporting, after adding the value, I convert the JSON string to an array, sort it, then convert it back to JSON format.

		//Starfish.LogMessage("Need to add reg to existing value");
		existing = existing.Replace(System.Environment.NewLine, "");
		existing = existing.Replace(" ","");
		string combined = existing.Replace("]","")+",\""+reg+"\"";
		combined = combined.Replace("[","");
		string[] combinedArray = combined.Split(',');
		for (int j = 0; j <= combinedArray.GetUpperBound(0); j++)
			//Starfish.LogMessage(combinedArray[j]+" ");
			result = result + combinedArray[j] + ",";

		result = result.TrimEnd(',');
		result = "["+result+"]";

    • Related Articles

    • Working with Cross References (Xref files)

      Working with Cross References (Xref files) Xref files servermany purposes. The most common case is as foreign key lookups. Another common case is to use Xrefs as pick list lookups. Tables can be created manually. They can be created by importing the ...
    • Working with Starfish Variables

       Starfish variables can be used to store configurable information used by jobs and scripts. In the example below, several Variables have been defined. Use the following steps to walk through Viewing variables Selecting and changing a variable ...
    • Look in many xref lists for an origin ID

      Function ScriptedField Dim newid Dim oldid oldid = "@@ORG:OLDID@@" newid = XrefRead("Accounts",oldid) If Len(newid) = 0 Then newid = XrefRead("Contacts",oldid) End If If Len(newid) = 0 Then newid = XrefRead("Opportunities",oldid) End If If Len(newid) ...
    • Hubspot Connector

      Hubspot Connector Note: As of September 8, 2020 the Hubspot API does not allow external applications to write into their Quoting module.  See below. Overview The StarfishETL Hubspot Connector enables you to easily connect to Hubspot for integrations ...
    • Active Directory Connector

      Origin There may be some trial and error with capitalization required to get this Origin working. For example, ldap:// vs LDAP:// or LDAP:// vs LDAP:// Parameter Description Access Key Connection String Active ...