Sample Integration Population Query

The following image displays a sample query “SNOW Biz Containment Biz 1.0” to be populated from ServiceNow:

Note that relationships are marked as Root, so in this case every Root element contains a pair of CIs, parent and child.

The following mapping file is created ServiceNowGenericAdapter/mappings/population/SNOW Biz Containment Biz 1.0.xml, and this is how it looks like in XML format:

<target_entities>
    <source_instance query-name="SNOW Biz Containment Biz 1.0" root-element-name="cmdb_rel_ci">
<target_entity is-valid="cmdb_rel_ci['parent_table'] == 'cmdb_ci_service'" name="BusinessService"> <target_mapping datatype="STRING" name="global_id" value="cmdb_rel_ci['parent']"/>
</target_entity>
<target_entity is-valid="cmdb_rel_ci['parent_table'] == 'cmdb_ci_appl'" name="BusinessApplication">
<target_mapping datatype="STRING" name="global_id" value="cmdb_rel_ci['parent']"/>
</target_entity>
<target_entity is-valid="cmdb_rel_ci['child_table'] == 'cmdb_ci_service'" name="BusinessService_1">
<target_mapping datatype="STRING" name="global_id" value="cmdb_rel_ci['child']"/>
</target_entity>
<target_entity is-valid="cmdb_rel_ci['child_table'] == 'cmdb_ci_appl'" name="BusinessApplication_1">
<target_mapping datatype="STRING" name="global_id" value="cmdb_rel_ci['child']"/>
</target_entity>
</source_instance> ...

Note how the structure of the mapping file follows the hierarchy in the TQL query, relationship as a Root, CIs on both ends.

You can limit the processing the result from the ServiceNow table cmdb_ci_rel by defining is-valid condition. In this example is-valid="cmdb_rel_ci['parent_table'] == 'cmdb_ci_service'", it checks if the value is coming from the cmdb_ci_service table.

Sometimes CIs in ServiceNow do not have a relationship defined between them, but one CI keeps the sys_id of another CI in one of its attributes. For example, cmdb_ci_network_adapter has the attribute cmdb_ci, which contains the sys_id of the host where this adapter resides. To handle this situation in the mapping file, you need to have a valid reference attribute on the ServiceNow side and use dot-walking in the mapping. For example, to populate Windows CI with related interfaces, create a mapping file like this:

<?xml version="1.0" encoding="UTF-8"?>
<integration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../mappings_schema.xsd">
  <info>
    <source name="SNOW" vendor="HP" version="9.40"/>
    <target name="SNOW" vendor="ServiceNow" version="7.0"/>
  </info>
  <import>
    <scriptFile path="mappings.scripts.SNOWUtils"/>
  </import>
  <!--
  Populate SNOW ESX Servers to uCMDB.
  -->
  <target_entities>
    <source_instance query-name="Windows with interfaces Population" root-element-name="cmdb_ci_win_server">
      <target_entity name="Root">
        <target_mapping datatype="STRING" name="global_id" value="cmdb_ci_win_server['correlation_id']"/>
        <target_mapping datatype="STRING" name="display_label" value="cmdb_ci_win_server['name']"/>
        <target_mapping datatype="STRING" name="name" value="cmdb_ci_win_server['name']"/>
        <target_mapping datatype="STRING" name="sys_id" value="cmdb_ci_win_server['sys_id']"/>
      </target_entity>
      <for-each-source-entity count-index="i" source-entities="cmdb_ci_win_server.cmdb_ci_network_adapter">
        <target_entity name="Interface">
          <target_mapping datatype="STRING" name="name" value="cmdb_ci_win_server.cmdb_ci_network_adapter[i]['name']"/>
          <target_mapping datatype="STRING" name="sys_id" value="cmdb_ci_win_server.cmdb_ci_network_adapter[i]['sys_id']"/>
          <target_mapping datatype="STRING" name="interface_name" value="cmdb_ci_win_server.cmdb_ci_network_adapter[i]['name']"/>
          <target_mapping datatype="STRING" name="mac_address" value="cmdb_ci_win_server.cmdb_ci_network_adapter[i]['mac_address']"/>
          <target_mapping datatype="STRING" name="global_id" value="cmdb_ci_win_server.cmdb_ci_network_adapter[i]['correlation_id']"/>
          <target_mapping datatype="STRING" name="root_container" value="cmdb_ci_win_server['correlation_id']"/>
        </target_entity>
      </for-each-source-entity>
    </source_instance>
  </target_entities>
</integration>