Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Decision table API is not creating correct choices

Jan Cernocky
Tera Guru

Hi guys,

I am playing with DT API and I am facing an issue that I cannot explain. 

I have the following Decision table

 

JanCernocky_0-1694594651895.png

I creat inputs, conditions, answer elements and I also create answer element choices for Loan Approval Decision (4th column) - Denied, Review, Approved

 

var answerElementChoices = [
   {
      label: 'Denied',
      value: 'denied',
      answerElementId: answerElementID,
      order: 100
   },
   { 
      label: 'Review', 
      value: 'review',
      answerElementId: answerElementID,
      order: 200
   },
   { 
      label: 'Approve', 
      value: 'approve',
      answerElementId: answerElementID,
      order: 300
   }
];

 

And then I create the Questions (rows in the DT)

 

var questions = [
    {
        active: true,
        answer: [
            {
                name: "u_loan_approval_decision" ,
                value: "denied"
            },
                    
        ],
        condition: "u_credit_score=poor^u_household_income<50000^u_loan_amount<200000^EQ",
        defaultAnswer: false,
        order: 100
    },
    {
        active: true,
        answer: [
            {
                name: "u_loan_approval_decision" ,
                value: "denied"
            },            
        ],
        condition: "u_credit_score=fair^u_household_income<50000^u_loan_amount<200000^EQ",
        defaultAnswer: false,
        order: 200
    }
]

var questionsResponse = dt.createQuestions(decisionId, questions);

 

However, instead of linking the Loan Approval Decision to corret choice (Denied, Review, Approved) it creates a new record. And then of course I am getting incorrect results when querying for the decisions.

 

JanCernocky_1-1694595032547.png

 

Any idea how to deal with that and what can be the problem? The documentation is very brief for this topic, the only example for createQuestions shows this:

 

JanCernocky_3-1694595256516.png

Which I believe is exactly what I am setting up.

2 REPLIES 2

Shruti
Mega Sage
Mega Sage

Hi,

Try this

var answerElementChoices = [
   {
      label: 'Denied',
      value: 'denied',
      answerElementID: answerElementID.toString(),
      order: 100
   },
   { 
      label: 'Review', 
      value: 'review',
      answerElementID: answerElementID.toString(),
      order: 200
   },
   { 
      label: 'Approve', 
      value: 'approve',
      answerElementID: answerElementID.toString(),
      order: 300
   }
];

Thanks for reply Shruti, unfortunately this did not help as I am already working with a string in the code

var answerElementID = answerElementsResponse.results[0].record.getValue('sys_id');

Moreover it is showing correctly in decision table view.

JanCernocky_1-1694602472714.png

But not in the record itself. Even the value for Review Group is missing

JanCernocky_0-1694602429113.png

It works well with strings

JanCernocky_2-1694602563373.png

JanCernocky_3-1694602574699.png