Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trouble with the IdentificationEngine API (createOrUpdateCI())

Mike Hashemi
Mega Sage

 

I am trying to use this API resource to create some CIs through a scripted REST endpoint, but there are two issues.

 

  1. When I send CI properties for a firewall and one of its interfaces, both CIs are created, but the manufacturer field of the firewall is blank. ServiceNow responds (I also tried sending the sys_id of the "Cisco" entry from the core_company table):

 

"info": [
                    {
                        "code": "SKIPPED_SETTING_REFERENCE_FIELD",
                        "message": "Table does not have a display value column: [core_company]. Skipped setting the reference field: [class: cmdb_ci_ip_firewall] [field: manufacturer] [value: Cisco]"
                    }
                ]

 

  • The JSON looks like this: 

 

[
    {
        "items": [
            {
                "className": "cmdb_ci_ip_firewall",
                "values": {
                    "os_name": "Cisco Adaptive Security Appliance Version 9.8(4)29",
                    "host_name": "asa01",
                    "ip_address": "10.0.0.1",
                    "name": "asa01"
                },
                "display_values": {
                    "manufacturer": "b7e831bdc0a80169015ae101f3c4d6cd"
                },
                "internal_id": "314",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            },
            {
                "className": "cmdb_ci_ni_interface",
                "values": {
                    "name": "id[06]",
                    "short_description": "Discovered by agent 20 via NSP collector",
                    "serial_number": "123456"
                },
                "internal_id": "18705013",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            }
        ]
    }
]​

 

  • Using that same JSON, but adding a relationship, I get back:

 

"errors": [
                {
                    "error": "INVALID_INPUT_DATA",
                    "message": "Payload relations '{\"parent\":314,\"child\":18705013,\"type\":\"Owns::Owned by\",\"sys_rel_source_info\":{\"source_recency_timestamp\":\"3/26/2023 2:35:17 PM\",\"source_name\":\"My custom source\"}}' has invalid parent record index: [314]"
                },
                {
                    "error": "INVALID_INPUT_DATA",
                    "message": "Payload relations '{\"parent\":314,\"child\":18705013,\"type\":\"Owns::Owned by\",\"sys_rel_source_info\":{\"source_recency_timestamp\":\"3/26/2023 2:35:17 PM\",\"source_name\":\"My custom source\"}}' has invalid child record index: [18705013]"
                }
            ]

 

  • With the relations node, the JSON looks like this:

 

[
    {
        "items": [
            {
                "className": "cmdb_ci_ip_firewall",
                "values": {
                    "os_name": "Cisco Adaptive Security Appliance Version 9.8(4)29",
                    "host_name": "asa01",
                    "ip_address": "10.0.0.1",
                    "name": "asa01"
                },
                "display_values": {
                    "manufacturer": "b7e831bdc0a80169015ae101f3c4d6cd"
                },
                "internal_id": "314",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            },
            {
                "className": "cmdb_ci_ni_interface",
                "values": {
                    "name": "id[06]",
                    "short_description": "Discovered by agent 20 via NSP collector",
                    "serial_number": "123456"
                },
                "internal_id": "18705013",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            }
        ],
        "relations": [
            {
                "parent": "314",
                "type": "Owns::Owned by",
                "sys_rel_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                },
                "child": "18705013"
            }
        ]
    }
]

 

Can anyone provide insight into these issues? How should I be pass the manufacturer reference field value and what is wrong with the parent and child identifiers in my relationship? Where should those values come from?

1 REPLY 1

petermueller
Tera Contributor

When using the "internal_id" fields  you need switch out your "parent" and "child" in relations with "parent_id" and "child_id".   

var payload = {
        "items": [
            {
                "className": "cmdb_ci_ip_firewall",
                "values": {
                    "os_name": "Cisco Adaptive Security Appliance Version 9.8(4)29",
                    "host_name": "asa01",
                    "ip_address": "10.0.0.1",
                    "name": "asa01"
                },
                "display_values": {
                    "manufacturer": "b7e831bdc0a80169015ae101f3c4d6cd"
                },
                "internal_id": "314",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            },
            {
                "className": "cmdb_ci_ni_interface",
                "values": {
                    "name": "id[06]",
                    "short_description": "Discovered by agent 20 via NSP collector",
                    "serial_number": "123456"
                },
                "internal_id": "18705013",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            }
        ],
        "relations": [
            {
                "parent_id": "314",
                "type": "Owns::Owned by",
                "sys_rel_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                },
                "child_id": "18705013"
            }
        ]
    };

var input = JSON.stringify((payload));
var output = sn_cmdb.IdentificationEngine.identifyCIEnhanced('Other Automated', input, {});

gs.info(JSON.stringify(JSON.parse(output), null, 2));

  The "parent" and "child" are looking for Items order.  See following example.

var payload = {
        "items": [
            {
                "className": "cmdb_ci_ip_firewall",
                "values": {
                    "os_name": "Cisco Adaptive Security Appliance Version 9.8(4)29",
                    "host_name": "asa01",
                    "ip_address": "10.0.0.1",
                    "name": "asa01"
                },
                "display_values": {
                    "manufacturer": "b7e831bdc0a80169015ae101f3c4d6cd"
                },
                "internal_id": "314",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            },
            {
                "className": "cmdb_ci_ni_interface",
                "values": {
                    "name": "id[06]",
                    "short_description": "Discovered by agent 20 via NSP collector",
                    "serial_number": "123456"
                },
                "internal_id": "18705013",
                "sys_object_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                }
            }
        ],
        "relations": [
            {
                "parent": "0",
                "type": "Owns::Owned by",
                "sys_rel_source_info": {
                    "source_recency_timestamp": "3/26/2023 2:35:17 PM",
                    "source_name": "My custom source"
                },
                "child": "1"
            }
        ]
    };

var input = JSON.stringify((payload));
var output = sn_cmdb.IdentificationEngine.identifyCIEnhanced('Other Automated', input, {});

gs.info(JSON.stringify(JSON.parse(output), null, 2));