The CreatorCon Call for Content is officially open! Get started here.

How to get the CI class name through REST API

David Casper
Tera Guru

We have an integration pulling CIs from the cmdb_ci table and need the class name rather than the actual table which is returned when you get the value for the cmdb_ci.sys_class_name field.

Curious how to pull the class name (not table name) through a REST call. 

getClassDisplayValue() method is used when scripting inside SNOW itself, but I can't seem to find out how to get that result through the API. 

Thanks!

 

1 ACCEPTED SOLUTION

Giles Lewis
Giga Guru

You can add "sysparm_display_value=all" to your URL. Here is an example

Script

#!/bin/bash
instance=********
username=********
password=********
sysid=a22be6f1dbfde7007c7e54f948961944
fieldnames=sys_id,name,manufacturer,sys_class_name
base="https://$instance.service-now.com/api/now/table/cmdb_ci/$sysid"
parms="sysparm_fields=$fieldnames&sysparm_display_value=all"
url="$base?$parms"
curl $url --request GET --user "$username:$password"

Output

{
    "result": {
        "sys_id": {
            "display_value": "a22be6f1dbfde7007c7e54f948961944",
            "value": "a22be6f1dbfde7007c7e54f948961944"
        },
        "name": {
            "display_value": "b24-rtr-2",
            "value": "b24-rtr-2"
        },
        "sys_class_name": {
            "display_value": "IP Router",
            "value": "cmdb_ci_ip_router"
        },
        "manufacturer": {
            "display_value": "Cisco",
            "link": "https://********.service-now.com/api/now/table/core_company/fc8318026fc8de002cc8186e6b3ee4ce",
            "value": "fc8318026fc8de002cc8186e6b3ee4ce"
        }
    }
}

View solution in original post

9 REPLIES 9

Giles Lewis
Giga Guru

You can add "sysparm_display_value=all" to your URL. Here is an example

Script

#!/bin/bash
instance=********
username=********
password=********
sysid=a22be6f1dbfde7007c7e54f948961944
fieldnames=sys_id,name,manufacturer,sys_class_name
base="https://$instance.service-now.com/api/now/table/cmdb_ci/$sysid"
parms="sysparm_fields=$fieldnames&sysparm_display_value=all"
url="$base?$parms"
curl $url --request GET --user "$username:$password"

Output

{
    "result": {
        "sys_id": {
            "display_value": "a22be6f1dbfde7007c7e54f948961944",
            "value": "a22be6f1dbfde7007c7e54f948961944"
        },
        "name": {
            "display_value": "b24-rtr-2",
            "value": "b24-rtr-2"
        },
        "sys_class_name": {
            "display_value": "IP Router",
            "value": "cmdb_ci_ip_router"
        },
        "manufacturer": {
            "display_value": "Cisco",
            "link": "https://********.service-now.com/api/now/table/core_company/fc8318026fc8de002cc8186e6b3ee4ce",
            "value": "fc8318026fc8de002cc8186e6b3ee4ce"
        }
    }
}

Simple things. Thanks a ton for the feedback. 

Have a great weekend!

How would this look in a perl script using Your ServiceNow::SOAP? 

I cant seem to get anything back unless I use the specific server type. 

Here is my current code. 

 

print "CI_ITEM:$ci_item\n";

        my $tablename = "cmdb_ci";

        my $table = $connect->table($tablename);

        my $fieldnames="sys_id,name,manufacturer,sys_class_name";

        my $rec = $table->getRecords(sys_id => $ci_item, __encoded_query => "sysparm_view=standard_change");

        #my $rec = $table->getRecords(sys_id => $ci_item, __encoded_query => "sysparm_fields=$fieldnames&sysparm_display_value=all");

print Dumper(@rec);

 

my $table = $connect->table('cmdb_ci');
my $rec = $table->setDV('all')->getRecord($ci_item);
print Dumper($rec);

Trabold
Mega Contributor

Thanks for this example.
Just to be complete - there is another parameter available which controls if the JSON tag "link" appears into the result or not:

sysparm_exclude_reference_link = true

Note that this is a) an exclusion and b) depends on "sysparm_display_value" (= "all").
If you set them to "true", "link" will never be provided, default: "false" (as by the given example)