Custom function to read from business object
Posted: Fri Sep 26, 2025 11:34 am
Right now I'm doing this:
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?
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"]);
}
}
Is there a way to do this?