Implement Python script and JSON configuration

Define your custom business logic in a Python script and expose it to the Detect UI using a JSON configuration file.

About this task

The system requires a defined Python script and an updated JSON file to register the new derived attribute function.

Procedure

  1. Create or update the Python file to define your custom logic.

    The function must accept the variables provided by the tuple (for example, the transaction amount) and the variables configured in the UI (for example, GST rate and surcharge amount).

    The following example demonstrates a function that calculates a GST amount and adds a fixed surcharge:

    def get_GST_on_transaction_amount_plus_some_fixed_surcharges(transaction_amount, gst_rate, surcharge_amount):
        # Calculate the GST value based on the rate (e.g., 18%)
        gst_value = transaction_amount * (gst_rate / 100)
        
        # Add the fixed surcharge amount (e.g., 5 rupees)
        total_value = gst_value + surcharge_amount
        
        # Return the computed value to the engine as a double
        return total_value
  2. Add the JSON entry to the configuration file.

    This entry maps the UI fields to the Python function, specifying the required tuple attributes (such as transaction amount) and the double values the user must configure (such as GST rate).

    Note:
    To retain a computed value for use by future tuples of the same entity, add a storeBackAttribute entry to the JSON. For more information, see the store back mechanism described in Store back mechanism
  3. Restart the Tomcat server and the engine.

    You must perform a restart because the engine fetches the available function definitions during startup. Without a restart, the newly added function won't appear in the derived directory section of the UI.