---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# IPAddressFixup - Global

# IPAddressFixup - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 minutes to read

The IPAddressFixup script include provides methods that ensure that no other device has the same IP address, after a device has been successfully discovered. If any duplicates are found, the IP address field
is cleared.

Use with any server-side Discovery script to validate IP addresses.

## IPAddressFixup - dedupe(String tableName, String ip) {#ariaid-title2}

Removes duplicates of the specified IP address in the specified table.
After a device has been successfully discovered, you can use the
dedupe() method to remove the duplicate IP addresses for that
device.
{#r_IPAF-dedupe_S_S__table_hsd_nnq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Table to check for duplicates. |
| ip | String | IP address to check for. |
[Table 1. Parameters]

{#r_IPAF-dedupe_S_S__table_hsd_nnq_pt} {#r_IPAF-dedupe_S_S__table_isd_nnq_pt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 2. Returns]

{#r_IPAF-dedupe_S_S__table_isd_nnq_pt}  
The following example shows how to use dedupe() in a background script
to remove duplicate IP addresses for the specified IP address within the cmdb_ci_hardware
table.

    var grDiscovery=new GlideRecord("discovery_device_history");
    grDiscovery.addQuery('sys_id','<sys id of the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference 
        fx.dedupe('cmdb_ci_hardware','192.161.1.1'); // Pass the IP address and table which removes duplicates of the specified IP address in the specified table.
      }

The following example shows how to use dedupe() in a business rule to
remove duplicate IP addresses for the specified IP address within the cmdb_ci_hardware
table.

    (function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        ipf.dedupe('cmdb_ci_hardware','168.128.1.1'); // Removes duplicates of the specified IP address in the specified table.
      }
    })(current, previous);

## IPAddressFixup - dedupeAll() {#ariaid-title3}

Removes all duplicate IP addresses from the tables.
{#r_IPAF-dedupeAll__table_fq1_hnq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#r_IPAF-dedupeAll__table_fq1_hnq_pt} {#r_IPAF-dedupeAll__table_gq1_hnq_pt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 4. Returns]

{#r_IPAF-dedupeAll__table_gq1_hnq_pt}  
The following example shows how to use dedupeAll() in a background
script to remove all duplicate IP addresses.

    var grDiscovery=new GlideRecord("discovery_device_history"); 
    grDiscovery.addQuery('sys_id','<sys id of the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
    {
      var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Call script include IPAddressFixup and pass cmdb reference
      fx.dedupeAll(); //Removes all duplicate IP addresses from the tables.
    }

The following example shows how to use dedupeAll() in a business rule to
remove all duplicate IP addresses.

    (function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
    {
      var ipf = new IPAddressFixup(cmdb_ci); //call script include IPAddressFixup and pass cmdb reference
      ipf.dedupeAll(); //Removes all duplicate IP addresses from the tables.
    })(current, previous);

## IPAddressFixup - fix() {#ariaid-title4}

Removes all duplicate IP addresses and ensures that the parent ip_address record is set
to one of the network interface card's (NIC) IP addresses.
After a device has been successfully discovered, you can use the
dedupe() method to remove the duplicate IP addresses for that device
and set the parent ip_address record value.
{#r_IPAF-fix__table_bfp_dmq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#r_IPAF-fix__table_bfp_dmq_pt} {#r_IPAF-fix__table_cfp_dmq_pt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 6. Returns]

{#r_IPAF-fix__table_cfp_dmq_pt}  
The following example shows how to use fix() in a background script to
remove duplicate IP addresses and set the parent IP address.

    var grDiscovery=new GlideRecord("discovery_device_history"); 
    grDiscovery.addQuery('sys_id','<sys id of the the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        fx.fix(); // Remove all duplicate IP addresses and ensure that the parent ip_address record is set to one of the NIC's IP addresses.
      }

The following example shows how to use fix() in a business rule to
remove duplicate IP addresses and set the parent IP address.

    (function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        ipf.fix(); /// Remove all duplicate IP addresses and ensure that the parent ip_address record is set to one of the NIC's IP addresses.
      }
    })(current, previous);

## IPAddressFixup - getParentIP() {#ariaid-title5}

Returns the parent IP address for the current device.
{#r_IPAF-getParentIP__table_ulc_1nq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#r_IPAF-getParentIP__table_ulc_1nq_pt} {#r_IPAF-getParentIP__table_vlc_1nq_pt__entry__2}

| Type | Description |
|-|-|
| String | Parent IP address |
[Table 8. Returns]

{#r_IPAF-getParentIP__table_vlc_1nq_pt}  
The following example shows how to use getParentIP() in a background
script to obtain the parent IP address.

    var grDiscovery=new GlideRecord("discovery_device_history"); // current.cmdb_ci can be used in case of Business rule on discovery_device_history table
    grDiscovery.addQuery('sys_id','<sys id of the the record>'); // sys_id of the device discovery_device_history
    grDiscovery.query();
    if(grDiscovery.next())
      {
        var fx=new IPAddressFixup(grDiscovery.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        gs.info(fx.getParentIP()); // Display the parent IP address of the device 
      }

Output:

    172.21.12.11

The following example shows how to use getParentIP() in a business rule
to obtain the parent IP address.

    ((function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        gs.log(ipf.getParentIP()); // Log the parent IP address of the device. Located in the system logs table 
      }
    })(current, previous);

## IPAddressFixup - setParentIP(String ip) {#ariaid-title6}

Sets the parent IP address field for the current CI.
{#r_IPAF-setParentIP_S__table_bgs_rmq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| ip | String | Parent IP address for the current CI. |
[Table 9. Parameters]

{#r_IPAF-setParentIP_S__table_bgs_rmq_pt} {#r_IPAF-setParentIP_S__table_cgs_rmq_pt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 10. Returns]

{#r_IPAF-setParentIP_S__table_cgs_rmq_pt}  
The following example shows how to use setParentIP() in a background
script to store the parent IP address.

    var grDiscover=new GlideRecord("discovery_device_history"); 
    grDiscover.addQuery('sys_id','a14e43b31bb4051070cb96c6b04bcb23'); // sys_id of the device in discovery_device_history table. Put your own sys_id here.
    grDiscover.query();
    if(grDiscover.next())
      {
        var fx=new IPAddressFixup(grDiscover.cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference.
        fx.setParentIP('197.111.1.1'); // Pass IP address to set as new IP on current mentioned CI.
      }

The following example shows how to use setParentIP() in a business rule
to store the parent IP address.

    ((function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Instantiate IPAddressFixup - pass cmdb reference
        fx.setParentIP('195.11.1.1'); // Set the new IP address of the CI 
      }
    })(current, previous);

## IPAddressFixup - syncIP() {#ariaid-title7}

Ensures that the parent ip_address record is set to one of the NIC's IP addresses, or
leaves it alone if there were no NICs.
{#r_IPAF-syncIP__table_ywk_kmq_pt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#r_IPAF-syncIP__table_ywk_kmq_pt} {#r_IPAF-syncIP__table_zwk_kmq_pt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 12. Returns]

{#r_IPAF-syncIP__table_zwk_kmq_pt}  
This shows an example of using the syncIP() method in a background
script.

    var grDevHistory=new GlideRecord("discovery_device_history");
    grDevHistory.addQuery('sys_id','a14e43b31bb4051070cb96c6b04bcb23'); // Sys_id of the device in discovery_device_history table. Put your own sys_id here.
    grDevHistory.query();
    if(grDevHistory.next())
      {
        var fx=new IPAddressFixup(grDevHistory.cmdb_ci); // Call the script include IPAddressFixup and pass cmdb reference
        fx.syncIP(); // Ensures that the parent ip_address record is set to one of the NIC's IP addresses, or leaves it alone if there were no NICs.
      }

This shows an example of using the syncIP() method in a business
rule.

    (function executeRule(current, previous /*null when async*/) {

    var cmdb_ci = current.cmdb_ci + '';
    if (cmdb_ci) 
      {
        var ipf = new IPAddressFixup(cmdb_ci); // Call script include IPAddressFixup and pass cmdb reference
        ipf.syncIP(); // Ensures that the parent ip_address record is set to one of the NIC's IP addresses, or leaves it alone if there were no NICs.
      }
    })(current, previous);


