- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 06:57 AM
Hi, i have an issue in the below condition.
In Incident table there is a list field = u_customers and in the Change request table there is = u_customers_impacted list column.
I want to compare if the list of customers in Incident table is available in Change request customer list and what are found i want to remove them from the incident list. From the below script, what ever is found is getting updated but when i use for updating only not found values, it is updating multiple times the same found value.
if (cust_arr_inc[i].indexOf(cust_arr_cr[j])>= 0) - this condition is updating the found values
but i want to do something like if (cust_arr_inc[i].indexOf(cust_arr_cr[j])<= 0) to update only not found values and it is repeating the customer names multiple times. Below is the complete script - please suggest.
var cust_found_arr = [];
var match = false;
var i = 0;
var j = 0;
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0170752');
gr.query();
while (gr.next()) {
var changeReq = new GlideRecord('change_request');
changeReq.addQuery('cmdb_ci', gr.cmdb_ci);
changeReq.query();
while (changeReq.next()) {
gs.print('the CR numbers matched is ' + changeReq.number);
var cust_arr_inc = [];
cust_arr_inc = gr.u_customers.toString().split(',');
gs.print('the Inc customers are ' + cust_arr_inc + gr.number);
var cust_arr_cr = [];
cust_arr_cr = changeReq.u_customers_impacted.toString().split(',');
gs.print('the CR customers are ' + cust_arr_cr + gr.number);
for (i = 0; i < cust_arr_inc.length; i++) {
for (j = 0; j < cust_arr_cr.length; j++) {
if (cust_arr_inc[i].indexOf(cust_arr_cr[j]) >= 0) {
cust_found_arr.push(cust_arr_inc[i]);
gs.print('The matched Companies are :' + cust_found_arr + ' - ' + gr.number);
}
}
}
}
}
if (cust_found_arr[0].length > 0) {
gr.setValue('u_customers', '');
gr.setValue('u_customers', cust_found_arr.toString());
gs.print('The Final Customer names are ' + gr.u_customers);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 08:12 AM
// Try this code
var cust_arr_inc = [];
var cust_arr_cr = [];
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0170752');
gr.query();
while (gr.next()) {
gs.print('the Inc customers are ' + cust_arr_inc.toString() + ' for ' + gr.number);
cust_arr_inc = gr.u_customers.toString().split(',');
var changeReq = new GlideRecord('change_request');
changeReq.addQuery('cmdb_ci', gr.cmdb_ci);
changeReq.query();
while (changeReq.next()) {
gs.print('the CR numbers matched is ' + changeReq.number);
var current_cr_cust = changeReq.u_customers_impacted.toString().split(',');
gs.print('the CR customers are ' + current_cr_cust.toString() + " for " + changeReq.number);
cust_arr_cr.concat(current_cr_cust); // collect into the array
}
}
var arrayUtil = new ArrayUtil();
gs.print("Not found Inc companies = " + arrayUtil.diff(cust_arr_inc, cust_arr_cr).toString());
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 08:34 AM
Sorry Formatting issue.
Sure -
Incident Company Sys ID's -
ff33c9b2db9a6b409afd309e7c9619a3,2db67f3fdbe31b009afd309e7c961934
CR Company Sys IDs -
f9b67f3fdbe31b009afd309e7c96197a,ff33c9b2db9a6b409afd309e7c9619a3
Incident sys ID for edb8f1b3db517700b90b7b6b8c9619cb
CR SYS ID for fa6ccbf0dbddb7809afd309e7c9619ec
Thanks for supporting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 08:40 AM
What is your expected result? What company sys ids are you expecting?
Run the below as a background script.
var inc = ['ff33c9b2db9a6b409afd309e7c9619a3','2db67f3fdbe31b009afd309e7c961934'];
var cr = ['f9b67f3fdbe31b009afd309e7c96197a','ff33c9b2db9a6b409afd309e7c9619a3'];
var arrayUtil = new ArrayUtil();
gs.print('CR does not contain these INC companies ' + arrayUtil.diff(inc, cr));
*** Script: CR does not contain these INC companies 2db67f3fdbe31b009afd309e7c961934
// You will still have to set the values and call update
gr.setValue('u_customers', arrayUtil.diff(inc, cr));
gr.update();
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 08:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 09:08 AM
On what table is the BR?
When does it run?
Screenshots please
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2019 09:14 AM