Hello, I'm reading a record that contains a text field I'd like to have listed in an array. However, the array should only have unique values, so if that text is already in there, I don't need to add it again. I've written this.
a!localVariables( local!arrayOfMakes, a!forEach( items: a!queryRecordType( recordtype: recordType!KD VM Vehicle, fields: recordType!KD VM Vehicle.fields.make, pagingInfo: a!pagingInfo( startindex: 1, batchSize: 50) ).data[recordType!KD VM Vehicle.fields.make], expression: if( contains(local!arrayOfMakes, fv!item), null, append(local!arrayOfMakes, fv!item) ) ) )
It returns what I think I need, but it's not unique. Here's part of the output. Further down you would see that it has several entries for the same make.
All ideas are appreciated!
Discussion posts and replies are publicly visible
You can use the union function to get unique values from the array instead of using an expression in foreach.
i.e. save results of the a!queryRecordType in a local and use union() on this result.
https://docs.appian.com/suite/help/21.3/fnc_set_union.html
union(local!arrayOfMakes, local!arrayOfMakes)
Further, I always recommend making a generic high-level helper rule for your entire system to use that takes a value and unions it against itself. An example from the old common objects pack was rule!APN_Distinct(), which takes any array and returns a de-duplicated copy of that array.