04-12-2019 11:25 AM
I have the input value stored in one string separated by delimiter comma. This value is available as Mapper variable.
For Example:
$inputstring - Value1,Value2,Value3,Value4,Value5
i have to separate these values and store separately in diff variables like mentioned below. Can anyone advise if there is any suitable functionality available for this. Anything in mapper will be helpful
Value1- Variable 1
Value2 - Variable 2
Value3 - Variable 3
Value4 - Variable 4
Value5 - Variable 5
04-12-2019 11:54 AM
I think you should be able to do a split.
The result would be an array and from that point you can assign each item in array to each variable.
Hope that helps!
04-12-2019 03:54 PM
Thanks for your response. It helps.
i separated using split function, but when i was trying to assign them using array for each variable like $myarray.find(x => x[1]), $myarray.find(x => x[2]), $myarray.find(x => x[3]), $myarray.find(x => x[4]) etc, only the first value of the array is assigned to all the variables. The subsequent values which were splitted/separated by comma are not assigned/showing up.
But i was able to use alternate method using substring and were able to assign. Can i know if i am missing something in array.
04-17-2019 07:05 AM
I wanted to explain why these expressions weren’t working. The find() method on arrays will iterate through the elements of the array and return the first element where the callback returned true. In this case, the callback supplied is indexing into the string (e.g. x[1] gets the second character in the string) and returning a character. Since a character is “truthy” the callback will always return true for the first element in the array and so that is being returned.
As mentioned in the other answer, you only really needed to add a second mapper where there were mappings that indexed into the array, like so: $myarray[0]
, $myarray[1]
, and so on.
04-13-2019 02:38 PM
Try this; I created an pipleine which took your input string, and then I used two mappers (should be able to make that one expression, but for simplicity, I used two). The first mapper takes the string and applies the split method:
$inputstring.split(',’)
And then the second takes the array produced there and extends the original document with the array as fields:
{}.extend($inputarray)
And here’s the output:
ConvertStringToFields_2019_04_13.slp (6.4 KB)