- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 05:27 AM
Hi All,
I Have a requirement to compare the two string fields data and the difference need to be populated in the 3rd field.
1st field name: user input
2nd field name: existing data
3rd field name: missing data:
1 st field data : 1,2,3,4,5,6
2nd field data : 2,5,6
i need to compare the data between 1st field and 2nd field and difference should be populate in 3rd field.
3rd field data: 1,3,4
Thanks in advance,
kumar
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 07:39 AM
I created an item in my dev instance and re-did the code. Try this you will just need to update the variable names as I created them as a, b, and c.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var a = g_form.getValue('a').toString().split(',');
var b = g_form.getValue('b').toString();
getDifference(a, b);
}
function getDifference(a, b)
{
// var j = 0;
var result = [];
for (var i = 0; i < a.length; i++){
if (b.toString().indexOf(a[i]) < 0){
result.push(a[i]);
}
}
g_form.setValue('c', result);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 07:10 AM
Hi bricast,
Thanks for your code. it is working with some issues.
input : 1,2,3,4,5,6,7,8
existing data : 1,2,4,5,7,8
after executing your code it is giving output like " 2,3,4,5,6,7,8"
even though the data is present in 2nd field ,it is not validating . can you please help me on it.
thanks,
kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 07:39 AM
I created an item in my dev instance and re-did the code. Try this you will just need to update the variable names as I created them as a, b, and c.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var a = g_form.getValue('a').toString().split(',');
var b = g_form.getValue('b').toString();
getDifference(a, b);
}
function getDifference(a, b)
{
// var j = 0;
var result = [];
for (var i = 0; i < a.length; i++){
if (b.toString().indexOf(a[i]) < 0){
result.push(a[i]);
}
}
g_form.setValue('c', result);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 07:51 AM
perfect..
Thank you so much bricast. it helped me alot.
kumar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 01:09 AM
Hi Bricast,
i have one issue with the output. can you please help on this.
input: adcshaketable02,QLE2460 LFD1025E12512,dileep,kumar
database data: adcshaketable02,QLE2460 LFD1025E12512,
missing servers Output: QLE2460 LFD1025E12512,dileep,kumar
issue: this server QLE2460 LFD1025E12512 is present in the data base. but due to space in the name it is not capturing while validating the data.can you help me to fix this issue.
i have used the below code which was suggested by you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var a = g_form.getValue('u_impacted_ci').toString().split(',');
var b = g_form.getValue('u_cmdb_ci_data').toString();
getDifference(a, b);
}
function getDifference(a, b)
{
// var j = 0;
var result = [];
for (var i = 0; i < a.length; i++){
if (b.toString().indexOf(a[i]) < 0){
result.push(a[i]);
}
}
g_form.setValue('u_missing_servers', result);
}
Thanks,
kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2018 04:59 AM
it worked for me. The space in the name should not matter as it is separating the names by the comma.