External enumerations again

We are integrating data from an external database and we need to use IDs in the A12 document to store the selection for dropdowns. As an example: our document model contains column named “AnredeID”. That ID needs to be taken from a table in that external database that stores the ID and display label (we can ignore localizations for now).

In the SME it’s possible to define a “external enumeration” for a form field. One of the options is the configuration of a “Source URL”

I assume that URL can point back to a controller in the backend (=“BAP Server”) that returns the IDs and the labels we have to use for that field.

But I cannot find any documentation on what that URL is supposed to return.

Can I return a key/value map (e.g. ID/title) so that the key is stored in the document, but the drop down displays the value? The value stored in the document needs to be the ID, not the display label (we have to replicate back some of the data in those document to the original system and that’s why we need the ID, not the label in our data).

Or does it need to return a list of ExternalEnumeration instances? That class has a “name” and “description”. Would the “name” map to the ID that I want to store?

Hi @thomas-soft-grove
In this scenario, your backend controller can simply return a key/value map containing the ID and title, as you mentioned. On the client side, you’ll need to define the IExternalEnumerationProvider for the relevant source configuration. The key (ID) will then be stored in the document.

Here is an example from Form Engine dev app (the Source URL in SME in this case is “config”):

// dummy data generator
function generateValues(): DocumentModel.ReadonlyObjectMap<{ [key: string]: string | undefined }> {
	let values: { [key: string]: { [key: string]: string | undefined } | undefined } = {};

	const entriesEnglish = [
		"Munich",
		"Aachen",
		"Bamberg",
		"Berlin",
		"Đà Nẵng",
		"Dresden",
		"Grenoble",
		"Hamburg",
		"Cologne",
		"Leipzig"
	];
	const entriesGerman = [
		"München",
		"Aachen",
		"Bamberg",
		"Berlin",
		"Đà Nẵng",
		"Dresden",
		"Grenoble",
		"Hamburg",
		"Köln",
		"Leipzig"
	];

	for (let i = 0; i < 10; i++) {
		const text: { [key: string]: string | undefined } = {
			de_DE: entriesGerman[i],
			en_US: entriesEnglish[i]
		};

		values = {
			...values,
			[entriesEnglish[i] + "_key"]: text
		};
	}

	return values;
}

let masterValues = generateValues();

/**
 * External enumeration provider that initially only provides the list of generated values.
 * This list is extended by entering custom values via respectively configured autocomplete controls.
 */
export const externalEnumerationProvider: IExternalEnumerationProvider = (
	source: string
): DocumentModel.ReadonlyObjectMap<{ [key: string]: string | undefined }> => {
	switch (source) {
		case "config": {
			return masterValues;
		}
		default:
			throw new Error("unknown external enumeration source: " + source);
	}
};

Hi @thomas-soft-grove ,

There is already an A12 ticket concerning this topic, A12-15058. Please add your use-case to the ticket. I would suggest also checking the ticket it was derived from A12-13704 to show what kind of complexities you might face with external enumerations.