I'm currently attempting to implement code that will take an IP address from one field, format it to include leading zeros, and then push that new format to a different field for sorting. I'm really new to coding and I'm having a difficult time trying to figure this out.
Example of what I'm expecting:
Field one value = 10.240.1.15
Format string and insert into Field2 = 010.240.001.015
I have it working in JSFiddle, but I'm having issues transferring this into Dynamics CRM.
function IPsort() {
var ipAddress = Xrm.Page.getAttribute("new_ipaddress").getValue();
var ipSort = Xrm.Page.getAttribute("new_ipsort");
function paddy(n, p, c) {
var pad_char = typeof c !== 'undefined' ? c : '0';
var pad = new Array(1 + p).join(pad_char);
return (pad + n).slice(-pad.length);
}
var num = paddy(ipAddress.split(".", 1)[0], 3) + '.' +
paddy(ipAddress.split(".", 3)[1], 3) + '.' +
paddy(ipAddress.split(".", 3)[2], 3) + '.' +
paddy(ipAddress.split(".", 4)[3], 3);
ipSort.setValue(num);
}
Any help would be greatly appreciated.
Thanks!
*This post is locked for comments
I have the same question (0)