Skip to content

Technical

Frontend

If you want to create a custom flow using the generate value functionality you can use the custom platform service ValueGeneratorService. It is available using a call to the platform.get function.

Web component example

import {
    ValueConfig,
    ValueGeneratorService,
    ValueGeneratorServiceName,
} from "src/services/value-generator.interface";

class MyComponent {
    private get valueGenerator(): ValueGeneratorService {
        return this.platform.get(ValueGeneratorServiceName);
    }

    public async generateValue() {
        const context = {
            limetype: "person",
            id: 1001,
        };
        const valueConfig = {
            formula: "{{ company.id }}",
        };

        const generatedValue = await this.valueGenerator.GenerateValue(
            context,
            valueConfig
        );
        console.log("The generated value", generatedValue);
    }
}

Service Interface

To use the service in the platform, the following file must be copied by hand to frontend/src/services/value-generator.interface.ts in your project.

import {
    LimeType,
    LimeWebComponentContext,
} from "@limetech/lime-web-components";

export const ValueGeneratorServiceName =
    "limepkg-standard-actions.value-generator.service";

declare module "@limetech/lime-web-components" {
    interface LimeWebComponentPlatform {
        get(service: typeof ValueGeneratorServiceName): ValueGeneratorService;
    }
}

export interface ValueGeneratorService {
    /**
     * Generate multiple values for a lime object.
     *
     * The values will be generated based on the provided value templates.
     *
     * The generated values will be type casted based on the limetype.
     *
     * The generated values will be returned as a record with the same keys as the value templates.
     *
     * If a value template has a formula, the formula will be evaluated (as jinja2) and the result will be returned.
     *
     * If a value template has a constant, the constant will be returned.
     *
     * If a value template has neither a formula nor a constant, null will be returned.
     *
     * If a value template has an expected output type, the value will be type casted to that type.
     *
     * If a value template has no expected output type, the value will be type casted to the type of the property in the limetype.
     *
     * @param limetype The limetype of the object, will be used for type casting each value.
     * @param context The context, what object the formula has as source.
     * @param valuesTemplate The value templates to generate.
     * @param customContext The extra optional object that the formula has as a source.
     * @returns The generated values.
     */
    GenerateValues(
        limetype: LimeType,
        context: LimeWebComponentContext,
        valuesTemplate: Record<string, ValueConfig>,
        customContext?: Record<string, unknown>
    ): Promise<Record<string, unknown>>;

    /**
     * Generate a single value.
     *
     * The value will be generated based on the provided value configuration.
     *
     * If the value config has an expected output type, the value will be type casted to that type.
     *
     * If the value config has no expected output type, the value will be type casted to the type of the given property in the context limetype.
     *
     * If the value config has no expected output type and no property name, the value will be casted to the best "guess" based on the value.
     *
     * If the value config has a formula, the formula will be evaluated (as jinja2) and the result will be returned.
     *
     * If the value config has a constant, the constant will be returned.
     *
     * If the value config has neither a formula nor a constant, null will be returned.
     *
     * @param context The context, what object the formula has as source.
     * @param valueConfig The value configuration.
     * @param propertyName The name of the property, used for type casting.
     * @param customContext The extra optional object that the formula has as a source.
     * @returns The generated value.
     */
    GenerateValue(
        context: LimeWebComponentContext,
        valueConfig: ValueConfig,
        propertyName?: string,
        customContext?: Record<string, unknown>
    ): Promise<unknown>;
}

export type OutputType =
    | "auto"
    | "int"
    | "float"
    | "str"
    | "datetime"
    | "list"
    | "bool";

export interface ValueConfig {
    constant?: unknown;
    formula?: string;
    expectedOutputType?: OutputType;
}

Backend

If you want to create a custom flow using the generate value functionality you can use our SDK package. It can be imported using limepkg_standard_actions.sdk

Python example

In the below example we expect that you have a LimeApplication called app

import limepkg_standard_actions.sdk as actions_sdk

source_limeobject = app.limetypes.get_limeobject("person", 1001)
value_config = {
    "formula": "{{ company.id }}",
}

generated_value =  actions_sdk.generate_value(
    app=app,
    context_object=source_limeobject,
    value_config=value_config,
)
logger.info(f"Generated value: {generated_value}")