how do you retrieve value column from sys_choice using table api

jsamm
Giga Contributor

Using table api with the following query

https://<site>/api/now/table/sys_choice?name=sometable&element=somecolumn

returns json

{

  "result": [

      {

          "label": "High"

      },

      {

          "label": "Medium"

      },

      //etc

  ]

}

How do you get the value column to be returned?   I've tried "sysparm_display_value=all".   I've tried "sysparm_fields=label,value".   Nothing works...when I specify a column that exists on the sys_choice table that is not "label" i get empty results...the correct number of results, but all empty

{

  "result": [

      {},

      {},

//etc

  ]

}

What i want is

{

  "result": [

      {

          "label": "High",

          "value": "1"

      },

      {

          "label": "Medium",

          "value": 2

      },

      //etc

  ]

}

Seems like a simple thing to do...can't seem to figure it out...when i query another table like incident with no filters or field specifications all the fields are dumped as expected...

1 ACCEPTED SOLUTION

jberk
Giga Expert

This is happening due to an ACL issue, the user doesn't have the "personalize choices" role so they only data on the sys_choice table they can see is the label, to correct this apply the "personalize", "personalize choices", or "personalize response"s role to the user you are running the query with and they should be able to see the rest of the fields on the sys_choice table. Alternatively you could alter the ACL that allows for all fields to be read on the sys_choice table.



-JB


View solution in original post

14 REPLIES 14

Kalaiarasan Pus
Giga Sage
Do you have access to read the data  on sys choice table?

I changed the role of the API user to include "Admin" and achieved no difference in results.   Are there permissions per column?   I can retrieve the label value.


Mike Allen
Mega Sage

The correct syntax would be:



api/now/table/sys_choice?sysparm_query=name=sometable^element=somecolumn



Capture.PNG



You have an ampersand (&) which should be a caret (^).