get answerID from DecisionTableAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 08:42 AM
I see the DecisionTableAPI and can happily use it to query and create and do what I want in that respect, but I have a scenario where I need to potentially add, update or remove and entries via a Script.
The examples in the Product Documentation all show answerID and then how to do the deletion or update. all good, but how do you get the answerID in the first place.
I can get answerID when I create a new entry and I can confirm that be creating an entry, taking the ID I can then edit or remove via the next functions.
I just cannot fathom (without side tracking off) how to get the answerID from their API - must be an easy way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 09:34 AM
Hey @JulianP32954866 ,
To retrieve the answerID from a ServiceNow Decision Table using the DecisionTableAPI, you can follow these steps:
**Initialize the DecisionTableAPI:
var dt = new sn_dt.DecisionTableAPI();
**Define the Input Parameters:
Create an object representing the inputs for the decision table. For example:
var inputs = {
u_country: 'USA',
u_location: 'New York',
u_employment_type: 'Full-Time'
};
**Call the Decision Table:
Use the getDecisions method to retrieve the decision results:
var response = dt.getDecisions('decision_table_sys_id', inputs);
**Access the answerID:
Iterate through the response to access the answerID:
var answerID = response[0].sys_id;
gs.info('Answer ID: ' + answerID);
This approach allows you to retrieve the answerID for further operations like updating or deleting entries....
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 03:54 AM
OK, let me clarify
I have an existing entry, I use the DecisionTableAPI to query the DT and get the response(s) that I need. At no stage does this provide an answerID which is what is needed if you want to edit or delete an existing entry.
I know how get it, but surprised it is not in the getDecision/getDecisions methods and wondered if I am missing something.
So if I query my table, I get an entry and the value of result_element.sys_id is c465dfd6834be210b9e29bc6feaad36d. That is not the answerID
If I query the "sys_decision_question" table and use the query answer=c465dfd6834be210b9e29bc6feaad36d, I get a record with the sys_id of 09f41bd6834be210b9e29bc6feaad356
When I use the DecisionTableAPI I have to use the 09f41bd6834be210b9e29bc6feaad356 to update the answer.I can do it and it is not hard, but just baffled I have to do something outside of the API to get the actual value of something I need
getAnswers needs the sys_id of the DT and returns all the basic info of all answers
getDecisions runs baed on the query and returns the decsion(s) that match. Great, but no answerID in the response
getQuestions is the only one I can see that gets me the "id" (09f41bd6834be210b9e29bc6feaad356) that is from the sys_decision_question table, but that is all questions and while I have some code that I can use to scan the array for an entry where the "value" matches my c465dfd6834be210b9e29bc6feaad36d sys_id. I am not sure if it is quicker to do this and process the JSON or just query the sys_decision_question table