How to use DecisionTableAPI with Decision Designer-built tables

Stefan Reichelt
Tera Guru
Tera Guru

Hi Community,

I just started evaluating Decision Builder, and I like it so much that I would like to use it even outside Flows but from scripts as well. As far as I understand, DecisionTableAPI is the right one to use for that purpose, but it only returns empty decisions to me. All the other methods are working, but not getDecision nor getDecisions. My test decision matrix in my PDI looks like this:

find_real_file.png

If I got it right, the code below should return a set of valid decisions (only 1 in this case) to me.

var dt = new sn_dt.DecisionTableAPI();
//var inputs = dt.getInputs("461b674407001110da93f2ae7c1ed00e");
//gs.info(JSON.stringify(inputs));
//var answers = dt.getAnswers("461b674407001110da93f2ae7c1ed00e");
//gs.info(JSON.stringify(answers));
var inputs = new Object();
inputs['u_where_am_i'] = 'in_the_city';
inputs['u_how_hungry_am_i'] = 'very_hungry';
var decision = dt.getDecisions('461b674407001110da93f2ae7c1ed00e', inputs);

gs.info(JSON.stringify(decision));

It only returns a JSON structure with fields but no values. Same for getDecision(): There I get a smaller JSON, but the values are still missing. Am I doing something wrong? Is this maybe even the wrong API? How is Flow Designer doing it in the background?

Best regards

1 ACCEPTED SOLUTION

Marc Mouries
ServiceNow Employee
ServiceNow Employee

The best practice is to call one or several decision tables in a subflow and then call the subflow. 

Anyway, if you print the entire response object it will show as empty but if you access the result directly you will get the expected value.

find_real_file.png

 

 

View solution in original post

4 REPLIES 4

Marc Mouries
ServiceNow Employee
ServiceNow Employee

The best practice is to call one or several decision tables in a subflow and then call the subflow. 

Anyway, if you print the entire response object it will show as empty but if you access the result directly you will get the expected value.

find_real_file.png

 

 

Hey @Marc Mouries , @Stefan Reichelt 

 

How can i give multiple input for querying the result from decision table ?

Below is the Input and Conditions for a decision table

NihalSarawgi1_0-1701629143270.png

 

var inputs = new Object();
inputs['u_company_code'] = "1000";
inputs['u_language'] = "English";
var decision = dt.getDecisions('decision table sys id', inputs);

gs.info(decision[0].result_elements.assignment_group.getDisplayValue());

 

Is this the correct way ?

My first line is looks like this:

var inputs = {};

 But I guess it may work your way, too.

Stefan Reichelt
Tera Guru
Tera Guru

Great! I was able to get a decision both ways. The API was remarkably faster, but I'll keep your recommendation in mind.

That made my day, thanks a lot!