Using String Array in Metric Cards

Hi,

I am trying to use string array in metric cards. However, I was not able to find a way to display it.

  • Metric Card widget is expecting a string variable.
  • I tried to convert the string array to a string via “variable transformation” but I was not able to find a way to do it.

Bottom-line is, how can I display a string array property of an object in metric cards?

Thanks,
Baris

There is currently no way to create a string variable from a string array using variable transforms. You could use a function backed string variable: https://www.palantir.com/docs/foundry/workshop/functions-use/#function-backed-variables-in-workshop

Hello!

If your object has a property of type array of strings the following solution will work:

  1. Create a string array variable in workshop and set it to an object property (use the object you are wanting to use in your metric card).

  2. Create a new code repository and write a Typescript function with input type as array of strings and output type as string. This function should loop and concatenate each of the strings with a separator/format of your choice and then return the concatenation of type string. Publish the function.

  3. Create a new string variable in workshop and select “function”. Choose the function you just published and then choose the string array variable you created in step 1 as the input. The output should be a string which you can display in a metric card.

Nicole

Old post, but guessing others have the same question:

  1. create a function, commit and tag version:
import {Function} from "@foundry/functions-api";

export class MyFunctions {

  @Function()
     public fromArrayToString(array: string[]): string {
     return array.join(", ");
  }

}

Returns a string “Value1, Value 2, Value 3”

  1. Create a string array from the property you want to stringify.
  2. Create a string based on a function. Select the function created in step 1. Select the array created in step 2 as input.
  3. Create a metric card, value type string, add the string created in step 3.

You can do it with variable transformation.

Please refer screenshots below.

String Array

Cast it to String from Variable transformation