Decision Table Error Using Business Rule

Alon Grod
Tera Expert

Hi, 

Why Im getting this error? What am I doing wrong?

This is my Decision table:

Screenshot 2024-06-16 at 18.43.17.png



This is my Business Rule:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var dt = new sn_dt.DecisionTableAPI();
    var inputs = {}
    inputs.u_category = current.category;
	inputs.u_name = 'alon';
    var response = dt.getDecision('542898e593be4210b73aba7efaba103a', inputs); //
    var result_a = response.result_elements.u_answer;

	gs.log('alonfsafas: ' + result_a);

})(current, previous);


This is the error that Im getting:

Screenshot 2024-06-16 at 18.55.42.png



6 REPLIES 6

Deepak Shaerma
Kilo Sage

Hi @Alon Grod 

The error message you are encountering indicates that the response object returned by dt.getDecision() is null. This suggests that either the Decision Table API call failed or the specific Decision Table ID and/or inputs do not exist or are not processed correctly.

1. Check if the Decision Table API is returning a valid response.

2. Add error handling and logging to capture more details about what might be going wrong.

also Try this script :

 

try {

        // Initialize DecisionTableAPI

        var dt = new sn_dt.DecisionTableAPI();

 

        // Prepare inputs for the Decision Table

        var inputs = {};

        inputs.u_category = current.category;

        inputs.u_name = 'alon';

 

        // Call the Decision Table and get the response

        var response = dt.getDecision('542898e593be4210b73aba7efaba103a', inputs);

 

        // Log the response object to see its structure

        gs.log('Decision Table Response: ' + JSON.stringify(response));

 

        // Check if response is valid

        if (!response) {

            gs.error('Decision Table Response is null');

            return;

        }

 

        // Check if result_elements exists in the response

        if (!response.result_elements) {

            gs.error('result_elements is null in the Decision Table response');

            return;

        }

 

        // Extract the result from the response

        var result_a = response.result_elements.u_answer;

 

        // Log the result

        gs.log('Decision Table Answer: ' + result_a);

    } catch (error) {

        gs.error('Error executing Decision Table: ' + error.message);

    }

 

please mark this Helpful and Accepted Solution if this helps you. Your action will help me and the community in understanding same requirements.

Thanks & Regards

Deepak Sharma

 

@Deepak Shaerma 
Im getting this log:

Screenshot 2024-06-16 at 19.16.55.png


But what am I doing wrong?

Screenshot 2024-06-16 at 19.19.08.png


James Chun
Kilo Patron

Hi @Alon Grod,

 

Try hard-coding the inputs for now, i.e. inputs.u_category = inquiry

If that works, it means you need to validate that your input is correct.

 

Also, I would recommend adding a Default result as well if applicable.

 

Cheers