Querying end point fields that has Space in it

Sathyanarayan K
Giga Contributor

Need help in GET request of Rest API by passing the fields in sysparm_fields.

 

I trying to query a Table via Rest API URI by passing only a limited number of columns of the table using Sysparam_fields.

 

However few column names have Spaces and parenthesis in it. So the JSON result set is excluding those columns and respective data when I do a GET request.

 

So if I am querying with column names  "assigned_to (need the empid)" and  "Number", I only get "Number" data.

If I dont pass, sysparm_fields it is returning the result set with all the columns including "assigned_to (need the empid)"

 

My end point looks like this

 

https://MyInstance.service-now.com/api/now/table/ticket?sysparm_exclude_reference_link=true&sysparm_... (need the empid)&sysparm_query=sys_updated_onBETWEENjavascript:gs.dateGenerate('2020-09-01','00:00:00')@javascript:gs.dateGenerate('2020-09-01','23:59:59')

 

The result is only 

 

{
    "result": [
        {
            "number""TK00001"
        }
}
 
If my URI is
 
 
Then I get the result
 
{
    "result": [
        {
            "number""TK00001",
            "assigned_to (need the empid)":"MYQ001",
            "Other_Field1":"Other Value 1",
             : 
             "Other_FieldN":"Other Value N"
        }
}
 
So how do I pass the column names that has Spaces and parenthesis like  "assigned_to (need the empid)"
 
Thanks for the Help in Advance
2 ACCEPTED SOLUTIONS

jaheerhattiwale
Mega Sage
Mega Sage

@Sathyanarayan K Actually "assigned_to (need the empid)" this field name is not valid as servicenow replaces spaces as _ in field name. But as you received it in response from the table api. This field might be created some how in the system.

 

You can try to replace the field name is URL from "assigned_to (need the empid)" to "assigned_to%20(need%20the%20empid)"

 

Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

Hi @Sathyanarayan K 

It seems that "assigned_to (need the empid)" is Column Names althought i don't know how to set the Column Names to a invalid value(I tried to change my column name to the same as yours, but i failed).

 

There is another parameter "sysparm_view" .

Create a new view just include the columns you need ,and run the restapi whith this parameter .

 

 

 

Please mark my answer as correct and helpful based on Impact.

View solution in original post

8 REPLIES 8

@Sathyanarayan K If this solution did not work then i will suggest to create a new field with proper name and then move data from "assigned_to (need the empid)" field to the new field through script. And then delete"assigned_to (need the empid)" this field.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Sathyanarayan K
Giga Contributor

Tried it... but It is not working. That field is not coming in response! It comes only if I remove sysparm_fields completely it is coming...

 

Yea somehow that Spaced Column Name or Column Label is sitting there causing issues. Unfortunately per business requirements, I can not ignore that field and also I can not bring all the data as its going to cost too much on performance front

Ankur Bawiskar
Tera Patron
Tera Patron

@Sathyanarayan K 

you should use column names in sysparm_fields and column name in servicenow won't contain any space

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sathyanarayan K
Giga Contributor

Thank you! Is there a way to get column names that I am not exposed to or not aware of from API response itself with some parameters?