Page 1 of 1

Custom function to read from business object

Posted: Fri Sep 26, 2025 11:34 am
by Tobias
Right now I'm doing this:

Code: Select all

public static class CustomFunctions
{
    public static string? GetValueByKey(StiBusinessObject businessObject, string key)
    {
        businessObject.Connect();
        try
        {
            if (businessObject.BusinessObjectValue is not IDictionary<string, string> dictionary) return null;
            return dictionary.TryGetValue(key, out var value) ? value : null;
        }
        finally
        {
            businessObject.Disconnect();
        }
    }

    public static void Register()
    {
        StiFunctions.AddFunction(
            category: "HELPERS",
            functionName: nameof(CustomFunctions.GetValueByKey),
            description: "Returns value by key from dictionary.",
            typeOfFunction: typeof(CustomFunctions),
            returnType: typeof(string),
            returnDescription: "The matching value or null",
            argumentTypes: [typeof(StiBusinessObject), typeof(string)],
            argumentNames: ["Dictionary", "Key"]);
    }
}
But I would like to chang this to a simpler "string GetDescription(string key)" and have the businessObject somehow hard-wired / looked up in the custom function.

Is there a way to do this?

Re: Custom function to read from business object

Posted: Mon Sep 29, 2025 9:13 pm
by Lech Kulikowski
Hello,

Unfortunately, it is not possible via a custom function.

In the compilation mode, you can add it in the Code tab.

Thank you.