Transform map help needed which looks into clearing fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 08:51 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 09:33 AM
Hi @snow_beginner ,
Use gr.update(); not gr.update;
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 10:50 AM
thanks for catching that. I have made the change, however it is still not clearing out the same value from the older device.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 11:22 AM
Hi @snow_beginner ,
if (gr.next()) {
gr.ip_address = '';
gr.update();
}
target.ip_address = source.managementipaddress; // add this in your script
}
})(source, map, log, target);
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 01:23 AM
I have already done the field mapping of ip_address to managmentipaddress. Does this still need to be added?