ServiceNow REST APIs returns empty string ("") in response if there is no value/data available for fields

Ripul
Kilo Contributor

Hi All,

ServiceNow REST APIs returns empty string ("") in response if there is no value/data available for fields.

Behaviour is same for all the APIs. Explaining same with one example as below:

REST API: https://{{instanceURL}}/api/now/table/sys_user/{{sys_user_id}}

Response: 

{
    "result": {
        "calendar_integration": "1",
        "country": "",
        "user_password": "",
        "last_login_time": "",
        "source": "",
        "sys_updated_on": "2021-10-28 13:01:39",
        "building": "",
        "web_service_access_only": "false",
        "notification": "2",
        "enable_multifactor_authn": "false",
        "sys_updated_by": "admin",
        "sys_created_on": "2021-10-28 05:52:14",
        "sys_domain": {
            "link": "https://{{instanceURL}}/now/table/sys_user_group/global",
            "value": "global"
        },
        "state": "MH",
        "vip": "true",
        "sys_created_by": "admin",
        "zip": "",
        "home_phone": "",
        "time_format": "",
        "last_login": "",
        "default_perspective": "",
        "active": "true",
        "sys_domain_path": "/",
        "cost_center": "",
        "phone": "",
        "name": " ",
        "employee_number": "",
        "password_needs_reset": "false",
        "gender": "",
        "city": "",
        "failed_attempts": "1",
        "user_name": "",
        "roles": "",
        "title": "",
        "sys_class_name": "sys_user",
        "sys_id": "sys_id_value",
        "internal_integration_user": "false",
        "ldap_server": "",
        "mobile_phone": "",
        "street": "",
        "company": "",
        "department": "",
        "first_name": "",
        "email": "",
        "introduction": "",
        "preferred_language": "",
        "manager": "",
        "locked_out": "false",
        "sys_mod_count": "4",
        "last_name": " ",
        "photo": "",
        "avatar": "",
        "middle_name": "",
        "sys_tags": "",
        "time_zone": "",
        "schedule": "",
        "date_format": "",
        "location": ""
    }
}

 

We tried using sysparm_display_value=true (e.g https://{{instanceURL}}/api/now/table/sys_user/{{sys_user_id}}?sysparm_display_value=true) parameter available in ServiceNow. APIs returns value as a null for some properties, but it doesn't returns value as null for all fields for which values are not available.

Could someone please help us know if there is any way using which we can get value as null for fields which doesn't have any values/data.

 

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes if the field is not having any value it would return empty string.

that is the OOB behavior with the table APIs

Regards
Ankur

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

Guilherme Corsi
Kilo Contributor

There are any params to change this default config? like replacing empty strings to null?

Best Regards,

Guilherme

davidhomer
Tera Contributor

This is pretty nasty implementation - it means we you use something like the .NET serializer it throws an exception because you've said that cpu_count is an empty string - this is not a valid value for an integer - it should be null.