- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 11:18 PM
Background script -
var macAddress = "D4:3B:04:EB:87:00";
var array = macAddress.split("|");
macAddress = array[0];
gs.info("inside 1 if : " + array[0]);
// return array[0];
if (macAddress) {
gs.info("inside 1 if : "+macAddress);
var deviceMac = '';
deviceMac = macAddress.toUpperCase().toString();
if (deviceMac.length >= 3 && deviceMac.length <= 17) {
gs.info("inside 2 if : "+ deviceMac);
deviceMac = deviceMac.replace(/\W/ig, '');
deviceMac = deviceMac.replace(/(.{2})/g, "$1-");
deviceMac = deviceMac.slice(0, -1);
gs.info("devicemac updated : "+ deviceMac );
}
}
**************************************************************************************************************
Field Map Script :-
answer = (function transformEntry(source) {
var macAddress = source.u__device_mac_address.toUpperCase().toString();
var array = macAddress.split("|");
macAddress = array[0];
//gs.info("inside 1 if : " + array[0]);
// return array[0];
if (macAddress) {
// gs.info("inside 1 if : " + macAddress);
// Input string should be one less in lenght than a qualified MAC address (17)
if (macAddress.length >= 3 && macAddress.length <= 17) {
// gs.info("inside 2 if : " + deviceMac);
// Remove all but alphanumeric characters
macAddress = macAddress.replace(/\W/ig, '');
// Append a colon after every two characters
macAddress = macAddress.replace(/(.{2})/g, "$1-");
macAddress = macAddress.slice(0, -1);
// gs.info("devicemac updated : " + deviceMac);
return macAddress;
}
}
else
return '';
})(source);
Please help me and assist where do i need to make changes in my field map script
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 09:18 AM
Hi Anup,
Please try to execute below script.
Script:
answer = (function transformEntry(source) {
var macAddress = source.u__device_mac_address.toString().toUpperCase();
var array = macAddress.split("|");
macAddress = array[0];
if (macAddress) {
var deviceMac = '';
deviceMac = macAddress.toString().toUpperCase();
if (deviceMac.length >= 3 && deviceMac.length <= 17) {
deviceMac = deviceMac.replace(/\W/ig, '');
deviceMac = deviceMac.replace(/(.{2})/g, "$1-");
deviceMac = deviceMac.slice(0, -1);
return deviceMac.toString();
}
} else {
return '';
}
})(source);
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions
Nagaraj Tofin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 11:51 PM
Hi,
I guess there was type mistake on below line:
var macAddress = source.u__device_mac_address.toUpperCase().toString();
Can you please try below:
answer = (function transformEntry(source) {
var macAddress = source.u_device_mac_address.toUpperCase().toString(); // I guess youdid typo on this line, it was source.u__device_mac_address
var array = macAddress.split("|");
macAddress = array[0];
//gs.info("inside 1 if : " + array[0]);
// return array[0];
if (macAddress) {
// gs.info("inside 1 if : " + macAddress);
// Input string should be one less in lenght than a qualified MAC address (17)
if (macAddress.length >= 3 && macAddress.length <= 17) {
// gs.info("inside 2 if : " + deviceMac);
// Remove all but alphanumeric characters
macAddress = macAddress.replace(/\W/ig, '');
// Append a colon after every two characters
macAddress = macAddress.replace(/(.{2})/g, "$1-");
macAddress = macAddress.slice(0, -1);
// gs.info("devicemac updated : " + deviceMac);
return macAddress;
}
}
else{
return '';
}
})(source);
Also can you please share what logs you are getting by uncommenting logs, where your code is reaching?
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 05:36 AM
Hi Anil,
Thanks for your response. The field source.u__device_mac_address is correct. The extra _ is present in source field still i am not getting the expected output.
Thanks !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 09:18 AM
Hi Anup,
Please try to execute below script.
Script:
answer = (function transformEntry(source) {
var macAddress = source.u__device_mac_address.toString().toUpperCase();
var array = macAddress.split("|");
macAddress = array[0];
if (macAddress) {
var deviceMac = '';
deviceMac = macAddress.toString().toUpperCase();
if (deviceMac.length >= 3 && deviceMac.length <= 17) {
deviceMac = deviceMac.replace(/\W/ig, '');
deviceMac = deviceMac.replace(/(.{2})/g, "$1-");
deviceMac = deviceMac.slice(0, -1);
return deviceMac.toString();
}
} else {
return '';
}
})(source);
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions
Nagaraj Tofin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2022 10:14 PM