"dynamic Enumerations" with the SME

Hi everybody.
I’m looking for a way to create “dynamic Enumerations” with the SME.

Here some more informations:

  • There ist given an editable string field in a repetition (i.e. [surname])
  • At a different spot of our application I would like to create a dropdown Menu with every unique Value of [surname].

Is it possible to get a resolution by strictly using the SME?

Thanks
Björn

Hi @bjoern-sharp-oak,

It depends what you mean when you say:

  • At a different spot of our application I would like to create a dropdown Menu with every unique Value of [surname].

You can:

  1. Model a filter in your Overview Model that allows you to select surnames from the list of existing surnames by setting an annotation. (Overview Model documentation)
  2. Model a drop-down menu that displays all the surnames from documents that you want to link with the document you are working on using a Binding in the Form Model. (Binding documentation)
  3. Model an External Enumeration that take the string values from an external data source and displays them like an enumeration. (Form Modeling documentation)

You have to use custom code to:

  1. Evaluate all previously entered strings in a document or list of documents and use these to make a dynamic enumeration in your form.

Which of these ideas matches your use-case?

Hi Malcom,
thanks for your quick response.
Because we don’t have an overview Model for this field and the the affected output field is part of an inline repeat itself it seems like the External Enumeration is the best option.
While using an External Enumeration a Source URL needs to be set. I don’t know how to use this attribute correctly.
Is it possible to set a reference to a (repeated) field of a Document Model in the SME? Or do we have to code it external with TypeScript?

Hi @bjoern-sharp-oak,
As a modeler, you can only set a URL. I’ll ask one of my colleagues to have a look at this for you.

You can also look at:
TPS Investigates: How to use an External Enumeration?

@bjoern-sharp-oak
the reply of @malcolm-silver-ice is valid for your requirement.
in fact the implementation concludes to the parts:

  • add external enumeration on string field of form model (via data configuration)
  • use an identifier for source url
  • create a external enum provider like shown in the TPS Investigates link shared by @malcolm-silver-ice (or technically described on getA12.com documentation for external enums: Redirecting… )
  • let the external enum provider use an selector for selecting the current data state of the activity
  • get values from the data → map and return

A custom example how this can be achived:

/**
 * This example demonstrates how to create externalEnumProvider hook that can be used in form engine implementation.
 */
import { useSelector } from "react-redux";

import { Activity, ActivitySelectors } from "@com.mgmtp.a12.client/client-core/lib/core/activity";
import { ReadonlyObjectMap } from "@com.mgmtp.a12.formengine/formengine-core/lib/models";
import IExternalEnumerationProvider from "@com.mgmtp.a12.formengine/formengine-core/lib/back-end/services/external-enumeration-provider";

export function createExternalEnumProvider(enumSources: ExternalEnumSources): IExternalEnumerationProvider {
    return (source: string) => enumSources[source] ?? {};
}

function transformDataLikeNeeded(document: Activity.Data.SingleDocumentData["document"]): {id: string, label: string}[] {
    return []
}

export function useEnumSources(activity: Activity): ExternalEnumSources {
    const activityData = useSelector(
        ActivitySelectors.data(
            activity.id
        )
    );
    const documentData = Activity.Data.SingleDocumentData.isInstance(activityData) ? activityData.document : undefined;
    const customEnumListFromData = documentData ? transformDataLikeNeeded(documentData) : []
    return {
        "custom-enum-list-identifier-aka-source-url": customEnumListFromData.reduce(
            (all, next) => ({ ...all, [next.id]: { de: next.label } }), {}
        )
    };
}

type ExternalEnumSources = {
    [key: string]: ReadonlyObjectMap<{ [key: string]: string | undefined }>;
};