Get unique names

Is there a way to get unique values for a specific field?
For example, get a list of unique names where name is a field in a HUGE query set.

nancy

Hi Nancy,

It does seem like unique is a sorely missing filter in the DataObject Query API, and would be a welcome addition.

In the meantime, we think that your best option would be to use the Grouped Accumulation API, whose result will be a map of unique values to their counts. You’d then simply ignore the counts and use the keys.

See:

https://docs.leidos-leaf.com/stable/3.10/leaf-concepts/metadata-driven-development/data-object-service/accumulations/#grouped-accumulation

https://docs.leidos-leaf.com/stable/3.10/framework/javascript/javascript-leaf-clients/js-accumulation/#grouped-accumulate

Nancy -
If your team is interested in filing a feature request for potential inclusion in LEAF’s upcoming roadmap, you can do so here: Sign in to LEAF at our Jira Service Desk. Please let me know if you’d like to pursue that option or need any assistance filing the request.
Thanks & hope all is well!

Ok. In react, I have:

  const tspiLedgerService = useService('tspi-ds');

  useEffect(() => {
    const propName = 'lastModifiedBy';
    const type = 'TspiLight';
    const query = Q.dataObjectQuery().addFilters(Q.types(type));
    const accumulator = 'MIN';

    const accumulation = Accumulation.of(query, propName, type, accumulator);

    (async () => {
      const result = await tspiLedgerService.dataObjectService.groupedAccumulate(
        accumulation
      );
      // eslint-disable-next-line no-console
      console.log(result);
    })();
  }, [tspiLedgerService.dataObjectService]);

BUT how do I import Accumulation. I tried:

import { DataObjectQueries as Q, DataObjectQuery, Accumulation } from ‘@leaf-framework/core’;

Error: cannot resolve?

Nancy

Nancy, it sounds like your IDE isn’t helping much; you may have better luck using the “search” bar in the top right of the Javascript API docs.

To be clear, you need to use core.GroupedAccumulation.of() (if using an Object), not the un-grouped Accumulation:

https://api.leidos-leaf.com/leaf/javadocs/javascript/3.10.0/classes/core.GroupedAccumulation.html#of

The import line and example usage is in the LKB article I linked in my first reply:

https://docs.leidos-leaf.com/stable/3.10/framework/javascript/javascript-leaf-clients/js-accumulation/#grouped-accumulate

import { GroupedAccumulation } from '@leaf-framework/core';

const groupedAccumulation = GroupedAccumulation.of(
  query,
  propName,
  type,
  accumulator,
  groupedPropName
);