- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 04:35 AM
HI Team,
Please help me on the below requirement.
var object1 =[{
"taskid":"INC5678",
"tasAcco":"Apple","
taskReg":"EMEA"},
"taskid":"INC1234",
"tasAcco":"Apple","
taskReg":"India"},
{"taskid":"Inc4321",
"tasAcco":"Nokia","
taskReg":"USA"
}]
var object2 =
[{
"taskid":"INC1234",
"tasAcco":"Apple","
taskReg":"India"},
{"taskid":"Inc4321",
"tasAcco":"Nokia","
taskReg":"USA"
}]
In the above 2 JSON data we need ignore the common records from Object1 as the combination of (taskid+tasAcco+taskReg) Remining with one records need to pick and create a incident with the details.
Please help me how to active it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 11:33 AM
@sri83 You try the below code which will return a unique value
var object1=[ {
"taskid": "INC5678",
"tasAcco": "Apple",
" taskReg": "EMEA"
},
{ "taskid": "INC1234",
"tasAcco": "Apple",
" taskReg": "India" },
{
"taskid": "Inc4321",
"tasAcco": "Nokia",
" taskReg": "USA"
} ];
var object2=[ {
"taskid": "INC1234",
"tasAcco": "Apple",
" taskReg": "India"
},
{ "taskid": "Inc4321",
"tasAcco": "Nokia",
" taskReg": "USA" }
];
var arr = [];//to store final result
var flag = 0;
object1.forEach(function(object1){
object2.forEach(function(object2){
if(object2.taskid == object1.taskid){
flag = 1;
}
});
if(flag != 1){
arr.push(object1);
}
flag = 0;
});
gs.info(JSON.stringify(arr));
Please mark the answer correct/helpful based on Impact.
Regards,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 05:13 AM
Hi @sri83 ,
Please use below script to get unique array:
var duplicateArr = [];
var finalArray = [];
object1.forEach(function (item) {
var combinedStr = item.taskid + ',' + item.tasAcco+','+item.taskReg;
if (duplicateArr.indexOf(combinedStr) < 0){
duplicateArr.push(combinedStr);
finalArray.push(item);
}
});
gs.log(JSON.stringify(finalArray));
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 06:41 AM - edited 02-24-2023 06:53 AM
Hi Ratnakr,
Thanks for the quick response.
I want to compare both JSON objects and filter the final data in Object3 to store the Data. so that i will use and create the tickets by using the info.
I am Not aware of it how remove the data and get the final data.Please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 11:33 AM
@sri83 You try the below code which will return a unique value
var object1=[ {
"taskid": "INC5678",
"tasAcco": "Apple",
" taskReg": "EMEA"
},
{ "taskid": "INC1234",
"tasAcco": "Apple",
" taskReg": "India" },
{
"taskid": "Inc4321",
"tasAcco": "Nokia",
" taskReg": "USA"
} ];
var object2=[ {
"taskid": "INC1234",
"tasAcco": "Apple",
" taskReg": "India"
},
{ "taskid": "Inc4321",
"tasAcco": "Nokia",
" taskReg": "USA" }
];
var arr = [];//to store final result
var flag = 0;
object1.forEach(function(object1){
object2.forEach(function(object2){
if(object2.taskid == object1.taskid){
flag = 1;
}
});
if(flag != 1){
arr.push(object1);
}
flag = 0;
});
gs.info(JSON.stringify(arr));
Please mark the answer correct/helpful based on Impact.
Regards,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2023 12:49 AM
Hi Rahul,
Thanks for the quick reply.
I want to validate 3 parameter at a time as taskId+Account+region if the anyone of the value is different then i need to pick the record and create a task for this account as well.
For ex one task is related with above combination but region USA now another record is having the same data but Region is India then we will pick the record and create a task.
Please help me on this