I have an object property of string datatype. The values are dynamic based on the object selection. I would like to create another variable that would be a substring of that value. I tried to use variable transformation but the string operations only contain concatenation. Please let me know if there is a way to achieve the desired result.
Hi, as you have noticed substring is not currently a supported variable transform.
The other way to accomplish this would be to make a variable that is function-backed, where the function performs the substring.
An example typescript implementation of the substr
function might look like this:
public substring(inputString: string, start : Integer, end? : Integer): string {
if ((end != null && end < start) || start < 0 || start > inputString.length){
throw new UserFacingError(`substring function was given invalid bounds for string: ${inputString}`);
}
return inputString.substring(start, end)
}
Hope this helps! You can also refer to the Functions documentation in-platform for how to publish a function and use it in Workshop.