Transform map help needed which looks into clearing fields.

snow_beginner
Mega Guru

Hi,

 

So the requirement is to create 3 transform maps on the tables network adapters, ip address and network node in the order of 100, 200 and 300 respectively. Because the adapter table needs to be populated first so the IP address table can refer to it

 

Basically what happens is an integration runs overnight and data is thrown in an inventory table and from there it needs to go to the 3 tables above via transform maps.

 

staging table = inventory table

target tables = network adapter first, then ip address and lastly network node.

 

For network adapters and ip address table, the requirement is simple that if it finds a record it updates it and if it doesn't find one then it creates it in those tables

 

For the network node however, the requirement is complex. The coalesce is on the name field. If it finds a record with the same name as the data that's come in to the staging table then it can update the relevant fields. If it doesn't find the name then don't create a record in this table. So far it is doing that.

 

However, one of the fields that needs to be updated on this network node table is the IP address field which is a string field. so the scenarios is as below:

 

1) Device A on network node table has IP Address 1234

1.1) Device B on network node table has IP address 5678

 

2) The integration runs overnight and with Device A and the IP Address change to 4567. This happens and that's good. Now we have

 

device A, IP Address = 4567

device B, IP Address = 5678

 

3) The next day integration runs overnight again and this time for Device B, the IP address is set to 4567, Device C, IP Address is 7890

 

What needs to happen is that device B needs to get updated with the new ip address value of 4567, but device A needs to have no IP address. It needs to wipe out the value of device A as its the same as the one for device B and there should not be a record of device C at all as it does not exist in the table. so it should look like

 

device A, IP Address = null

device B, IP Address = 4567

 

I hope this made sense, please help me out. I have made a transform script on the transform map with this and its when value = onBefore

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    if (action == "insert") {
        ignore = true;
    }

    if (source.managementipaddress != '') {
        var gr = new GlideRecord('u_cmdb_ci_bt_network_node');
        gr.addQuery('ip_address', source.managementipaddress);
        gr.query();
        if (gr.next) {
            gr.ip_address = '';
            gr.update;
        }
    }

})(source, map, log, target);

Can I achieve this requirement?

 

6 REPLIES 6

Hi @snow_beginner ,

 

Its not required, But check the mappings properly, check by adding script if it is updating.

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

Hi @Anand Kumar P  

I think the mapping is correctScreenshot 2024-12-09 095017.png