So I have a local variable in an expression rule. Is there a way to set that value as the return value of the expression rule?
Discussion posts and replies are publicly visible
No prob - here's a streamlined version I created that demonstrates how this would probably work best for you (though you'll need to figure out a way to re-add the calculation for radiusThreshold at some point, but just for example:
/* Define the local variables for the function */ a!localVariables( /*Will hold the table from the query that will be looped through*/ local!offices: a!queryEntity( entity: cons!Geo_locationDBE, query: a!query( logicalexpression: a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "Location_ID", operator: "not includes", value: "DUMMY" ) } ), selection: a!querySelection(columns: { a!queryColumn(field: "Location_ID"), a!queryColumn(field: "Area_Name"), a!queryColumn(field: "Longitude"), a!queryColumn(field: "Latitude"), a!queryColumn(field: "Zipcode"), }), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: -1 ) ) ), local!officeDistances: a!forEach( items: local!offices, expression: rule!Geo_computeDistanceBetween( ri!Longitude, ri!Latitude, fv!item.Longitude, fv!item.Latitude ) ), local!closestDistance: min(local!officeDistances), /* find closest office (assumes no duplicate distances) */ local!closestOffice: index( local!offices.data, /* edited */ where(local!officeDistances = local!closestDistance) ), local!closestOffice )
Do you know of a simple way to index a datasubset?
yes - just add ".data" after the local variable name, i.e. "local!offices.data" might be necessary in my example above since it looks like your query returns a dataSubset instead of a data array.