This topic contains 5 replies, has 3 voices, and was last updated by  Sandeep 3 years, 1 month ago.

How to call functions based on their name(String)

  • Hi,

    I have a requirement to call functions from a util class but the name of functions I want to get from a text file. How can I achieve this?

    local util = require ‘util’

    function main()
    –logic to read mapping txt file.

    –if line = ‘randomGenerator()’
    –call randomGenerator() function from util class

    if line = ‘handleDefaultValue(‘value’, ‘defaultValue’)’
    –call function handleDefaultValue( value, defaultValue) from util class
    –here I am getting the args too.


    local util = {}

    function util.randomGenerator()
    –random generation logic

    function util.handleDefaultValue( value, defaultValue)

    –if value is blank then value = default value

    return util

    Rule file.txt

    util.handleDefaultValue(’50’, ‘100’)
    OR I can provide in below format too.
    util.handleDefaultValue(‘570’, ‘100’)
    util.handleDefaultValue(‘0’, ‘100’)

    Thank you in advance

    This sounds like what you’re looking for:

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊

    Hi Jeff,

    Thank you for the link.


    Hi Jeff,

    So I should define my function code as a string in my Rulefile. txt and in Iguana, use loadString to execute that code.

    In the screenshot, yellow will come from rulefile.

    Is there any other better way to implement this? I just want to write my function name with parameters and in Iguana based of name, I want to call the function with parameters.

    Thanks in advance

    You must be logged in to view attached files.

    What is your use case? Any reason that you need drive the program flow via file?

    Hi James,

    I have a requirement of converting CSV data to XML but I don’t have fixed XML template, so I designed a workflow in a way that I will create XML during channel run time and pick CSV column to XML field mapping from another XML file. Sometimes, I need to pre-process the CSV field and I want to keep this function name in the same mapping XML file


You must be logged in to reply to this topic.