- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 07:03 AM
If condition is not working properly.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 07:07 AM
try this and better to use an array
var excludedIds = [
'f6d8b512db4797009a88b1b2399619d4',
'8ce740824f684b00a032ecd18110c7af',
'48bd939a1be1fcd0e3bfa9b1604bcbc9',
'950045221be93014e3bfa9b1604bcb96',
'0174e3021b253cd0e3bfa9b1604bcb21',
'6aef35cc1b4354d0c592dc29cd4bcb28',
'34b2bbde1b32d490c592dc29cd4bcb79',
'1ecd222a1bb61890c592dc29cd4bcb23',
'574687a61b7a1890c592dc29cd4bcb69',
'b32831481b0354d0c592dc29cd4bcb0d',
'f7cc79881b4354d0c592dc29cd4bcb2f',
'42dc1c2f1b000d10e3bfa9b1604bcb80'
];
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('sys_id', current.sysapproval);
gritem.query();
if (gritem.next()) {
var catalog_item1 = gritem.cat_item.toString();
if (excludedIds.indexOf(catalog_item1.toString()) == -1) {
gs.addInfoMessage("Testing approvals");
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 07:07 AM
try this and better to use an array
var excludedIds = [
'f6d8b512db4797009a88b1b2399619d4',
'8ce740824f684b00a032ecd18110c7af',
'48bd939a1be1fcd0e3bfa9b1604bcbc9',
'950045221be93014e3bfa9b1604bcb96',
'0174e3021b253cd0e3bfa9b1604bcb21',
'6aef35cc1b4354d0c592dc29cd4bcb28',
'34b2bbde1b32d490c592dc29cd4bcb79',
'1ecd222a1bb61890c592dc29cd4bcb23',
'574687a61b7a1890c592dc29cd4bcb69',
'b32831481b0354d0c592dc29cd4bcb0d',
'f7cc79881b4354d0c592dc29cd4bcb2f',
'42dc1c2f1b000d10e3bfa9b1604bcb80'
];
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('sys_id', current.sysapproval);
gritem.query();
if (gritem.next()) {
var catalog_item1 = gritem.cat_item.toString();
if (excludedIds.indexOf(catalog_item1.toString()) == -1) {
gs.addInfoMessage("Testing approvals");
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 07:56 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 09:09 AM
Hi @Sanjeeva Nagend
The if condition in your script is not working as expected because of the use of the OR operator when you intend to check if catalog_item1 is different from all the specified sys_ids. As it is always evaluating to true.
you need to use the AND operator.
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('sys_id', current.sysapproval);
gritem.query();
if (gritem.next()) {
var catalog_item1 = gritem.cat_item.toString();
if (
(catalog_item1 != 'f6d8b512db4797009a88b1b2399619d4') &&
(catalog_item1 != '8ce740824f684b00a032ecd18110c7af') &&
(catalog_item1 != '48bd939a1be1fcd0e3bfa9b1604bcbc9') &&
(catalog_item1 != '950045221be93014e3bfa9b1604bcb96') &&
(catalog_item1 != '0174e3021b253cd0e3bfa9b1604bcb21') &&
(catalog_item1 != '6aef35cc1b4354d0c592dc29cd4bcb28') &&
(catalog_item1 != '34b2bbde1b32d490c592dc29cd4bcb79') &&
(catalog_item1 != '1ecd222a1bb61890c592dc29cd4bcb23') &&
(catalog_item1 != '574687a61b7a1890c592dc29cd4bcb69') &&
(catalog_item1 != 'b32831481b0354d0c592dc29cd4bcb0d') &&
(catalog_item1 != 'f7cc79881b4354d0c592dc29cd4bcb2f') &&
(catalog_item1 != '42dc1c2f1b000d10e3bfa9b1604bcb80')
) {
gs.addInfoMessage("Testing approvals");
}
}
However, as suggested by @Ankur Bawiskar, the array approach makes it easier to manage the list of sys_ids and for better maintenance of a long list of IDs
Regards,
Rohit Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 11:43 AM
The problem is with your condition logic:
if ((catalog_item1 != 'A') || (catalog_item1 != 'B') || ...)
This condition will always be true, no matter what the catalog_item1 is. You can use AND(&&) for !=, or use Array.includes()
Option 1:
var excludedItems = [
'f6d8b512db4797009a88b1b2399619d4',
'8ce740824f684b00a032ecd18110c7af',
'48bd939a1be1fcd0e3bfa9b1604bcbc9',
'950045221be93014e3bfa9b1604bcb96',
'0174e3021b253cd0e3bfa9b1604bcb21',
'6aef35cc1b4354d0c592dc29cd4bcb28',
'34b2bbde1b32d490c592dc29cd4bcb79',
'1ecd222a1bb61890c592dc29cd4bcb23',
'574687a61b7a1890c592dc29cd4bcb69',
'b32831481b0354d0c592dc29cd4bcb0d',
'f7cc79881b4354d0c592dc29cd4bcb2f',
'42dc1c2f1b000d10e3bfa9b1604bcb80'
];
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('sys_id', current.sysapproval);
gritem.query();
if (gritem.next()) {
var catalog_item1 = gritem.cat_item.toString(); // ensure it's a string
if (!excludedItems.includes(catalog_item1)) {
gs.addInfoMessage("Testing approvals");
}
}
option 2:
if (
catalog_item1 != 'A' &&
catalog_item1 != 'B' &&
catalog_item1 != 'C'
) {
// true only if it's not any of them
}
Please mark this response as correct and helpful if it helps you