Vlocity Facts #41 || Custom Function to Convert List of Values into Array of Values in DataMapper Formula
In one of the post we used SPLIT() function [Reference - DataMapper - Function and Formulas] to split the string. In response we received list of values.
Consider one scenario where you have selected multiple values from multi select picklist called Products.
In json we will get the response of the multiple select picklist with combination of semi colon[;]. If we need to create child records for those values it is not directly possible, so to divide those values we will use SPLIT() function with splitToken as semicolon [;].
Response:
Now we need to use custom function - apex class to convert list of values into array of values.[Similar post where we used custom function to calculate the difference between datatime fields: Using Custom Function in DataMapper]
By referring above mentioned post we will create one more method in the same apex class by writing logic in it.
I have made some changes to invokemethod by adding 'else If'
And added 'listToArray' Method logic to same apex class.
If we are using Function() in fomula tab and passing List() as input we need to use 'VLOCITY-FORMULA-LIST' to get the list of values in apex class.
FUNCTION('dateTimeDiffFinder','lsitToArrayConverter',LIST(%Products%))
If you observe I'm using same apex class but method name and input are different.Response:
In response you can observe node name with Products is related to SPLIT() function and ListTOArrayProducts [list to array of values with keys] is related to the custom function which we implemented through apex class and we can pass that json to DataMapper Post to create records.
Comments
Post a Comment