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.

Automation on Decision table record insertion

elanrajad
Tera Contributor

Can you please help me someone on below query.

I have a requirement to insert a row into the decision table via a scripting flow, where I have an input variable value and an output variable. The input variable references the schedule table, and the output variable references the group table.

 

1 ACCEPTED SOLUTION

Hello @elanrajad ,

 

Have you tried unchecking the "Enable draft authoring" box?

 

Regards,

Robert

View solution in original post

13 REPLIES 13

Robert H
Mega Sage

Hello @elanrajad ,

 

You can use the DecisionTable API to create new decisions, for example:

 

var decisionID = 'SYS_ID_OF_DECISION_TABLE';
var questions = [
   {
      condition: 'u_schedule=SYS_ID_OF_SCHEDULE_1',
      answer:[
         {
            name: 'u_group',
            value: 'SYS_ID_OF_GROUP_1'
         }
      ],
      active: true,
      defaultAnswer: true,
      order: 100
   },
   {
      condition: 'u_schedule=SYS_ID_OF_SCHEDULE_2',
      answer:[ 
         {
            name: 'u_group',
            value: 'SYS_ID_OF_GROUP_2'
         }
      ],
      active: true,
      defaultAnswer: false,
      order: 150
   }
];

var dt = new sn_dt.DecisionTableAPI();
var response = dt.createQuestions(decisionID, questions);
gs.info(JSON.stringify(response));

 

The above example assumes that your input is named "Schedule" and the output is named "Group", and that both  have the "Reference" type.

 

Regards,

Robert

 

Hi @Robert H  Thanks for your response 

when am trying via background script its giving below error how can we over come ?

elanrajad_0-1748509313170.png

@Ankur Bawiskar you have any suggestions

Hello @elanrajad ,

 

Looks like the Draft authoring feature is enabled for this Decision table.

 

You need to click Create Draft before running the script, or disable the feature.

 

RobertH_0-1748511719830.png

 

Regards,

Robert

 

 

Hi @Robert H 

I have tried where decision table is in draft mode and publish mode as well its not working for  me

 

elanrajad_0-1748514979511.pngelanrajad_1-1748515019383.png

The below is the script am running from background script 

var decisionID = '226c6cf98331221009799d60ceaad316';
var questions = [
   {
      condition: 'u_schedule=f86b71e3672322004792adab9485ef19',
      answer:[
         {
            name: 'u_decision_output',
            value: '553032e853165110b846ddeeff7b12aa'
         }
      ],
      active: true,
      defaultAnswer: true,
      order: 100
   }
 
];

var dt = new sn_dt.DecisionTableAPI();
var response = dt.createQuestions(decisionID, questions);
gs.info(JSON.stringify(response));