- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 12:15 AM
Hi,
I have a requirement, where I need to find if extension ITSR is raised for the user, then need to check if Leaver is raised. In case raised, then it should be cancelled. I wrote below code to get the variable value in array but it is not getting any value.
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('cat_item=89f0fe701b1af300e18764606e4bcb8d^state=1^ORstate=2');
gr.query();
while(gr.next()){
gs.log("inside while");
//usr = gr.variables.u_windows_id;
usr.push=gr.getValue(gr.variables.u_windows_id);}
gs.log('usr1 '+usr);
Kindly help!!
Regards,
Shivani
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:26 AM
@Shivani29 - I've tried to simplify the script a bit, please refer to the script below, it will only enter the if block if the value in usr array is same as the value in loginID array
var usr = [];
var loginID = [];
var ritmGR1 = new GlideRecord('sc_req_item');
ritmrGR1.addEncodedQuery('cat_item=89f0fe701b1af300e18764606e4bcb8d^state=1^ORstate=2');
ritmGR1.query();
while (ritmrGR1.next()) {
gs.log("inside while");
usr.push(ritmGR1.variables.u_windows_id.getDisplayValue());
}
gs.log('usr1 ' + usr);
var ritmGR2 = new GlideRecord('sc_req_item');
ritmGR2.addEncodedQuery('cat_item=65c6d644378c17c01ecacea954990ea5^state=1^ORstate=2');
ritmGR2.query();
gs.log('count ' + ritmGR2.getRowCount());
while (ritmGR2.next()) {
gs.log("inside ls while");
loginID.push(ritmGR2.variables.u_employee_login_id.getDisplayValue());
}
gs.log('loginId1 ' + loginID);
for (var i = 0; i < loginID.length; i++) {
for (var x = 0; x < usr.length; x++) {
gs.log('x n i ' + x[0] + i[0]);
if (usr[x] == loginId[i]) {
gs.log('inside ls if');
ritmGR2.setValue('state', 4);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 12:10 AM
Hi,
Thank you both for your reply. I tried and it is working now. However I am stuck on another block. I checked the values for x[0] and i[0] and both are undefined. Below is the script:
- var usr = [];
- var user;
- var ls;
- var i=0;
- var x =0;
- var loginId =[];
- var length;
- var gr = new GlideRecord('sc_req_item');
- gr.addEncodedQuery('cat_item=89f0fe701b1af300e18764606e4bcb8d^state=1^ORstate=2');
- gr.query();
- while(gr.next()){
- gs.log("inside while");
- usr.push(gr.variables.u_windows_id.getDisplayValue());}
- gs.log('usr1 '+usr);
- var length1 = usr.length;
- ls = new GlideRecord('sc_req_item');
- ls.addEncodedQuery('cat_item=65c6d644378c17c01ecacea954990ea5^state=1^ORstate=2');
- ls.query();
- gs.log('count '+ls.getRowCount());
- while(ls.next()){
- gs.log("inside ls while");
- loginId.push(ls.variables.u_employee_login_id.getDisplayValue());}
- gs.log('loginId1 '+loginId);
- length = loginId.length;
- gs.log('length '+length);
- for(i=0;i<length;i=i+1){
- gs.log('inside for1');
- for(x=0;x<length1;x=x+1){
- gs.log('inside for2');
- gs.log('x n i '+x[0]+i[0]);
- if (usr[x] == loginId[i]){
- gs.log('inside ls if');
- ls.setValue('state',4);}
- }}
At row# 30, i added logs to get value in usr[0] and loginId[0] but I am getting values as undefined. However on row# 14 and 23, I am getting values in arrays usr and loginId.
Kindly assist.
Regards,
Shivani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 12:46 AM
@Shivani29 - line 30 should be
gs.log('x n i '+ usr[x]+ loginID[i]);
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 01:09 AM
Thanks Karan. I got the values. But it is still not going inside if loop. Is this the right way to compare 2 array values?
Regards,
Shivani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:26 AM
@Shivani29 - I've tried to simplify the script a bit, please refer to the script below, it will only enter the if block if the value in usr array is same as the value in loginID array
var usr = [];
var loginID = [];
var ritmGR1 = new GlideRecord('sc_req_item');
ritmrGR1.addEncodedQuery('cat_item=89f0fe701b1af300e18764606e4bcb8d^state=1^ORstate=2');
ritmGR1.query();
while (ritmrGR1.next()) {
gs.log("inside while");
usr.push(ritmGR1.variables.u_windows_id.getDisplayValue());
}
gs.log('usr1 ' + usr);
var ritmGR2 = new GlideRecord('sc_req_item');
ritmGR2.addEncodedQuery('cat_item=65c6d644378c17c01ecacea954990ea5^state=1^ORstate=2');
ritmGR2.query();
gs.log('count ' + ritmGR2.getRowCount());
while (ritmGR2.next()) {
gs.log("inside ls while");
loginID.push(ritmGR2.variables.u_employee_login_id.getDisplayValue());
}
gs.log('loginId1 ' + loginID);
for (var i = 0; i < loginID.length; i++) {
for (var x = 0; x < usr.length; x++) {
gs.log('x n i ' + x[0] + i[0]);
if (usr[x] == loginId[i]) {
gs.log('inside ls if');
ritmGR2.setValue('state', 4);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 04:37 AM
Hi Karan,
Tried this script as well. There is 1 value which is present in both the arrays but still not going inside if.
Regards,
Shivani