- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 04:13 AM - edited 05-20-2025 04:14 AM
My requirement is 'ent contains==>> 0678191f1b13a4d06c3c2f007e4bcb9b,5b806c328396c6105fc86770deaad354', if '5b806c328396c6105fc86770deaad354' is found then remove it. entitlementIds should only contain '0678191f1b13a4d06c3c2f007e4bcb9b'. Can someone please help, TIA!
Script include
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 04:38 AM
try this
var entitlementIds = this.getADLDSEntitlement(ritm);
var corp = ritm.variables.corp_or_byod.getValue();
var emaildata = ritm.variables.emaildata.getDisplayValue();
var intunemdm = gs.getProperty('intune.mdm.corp.mobile');
var ent = entitlementIds.split(',');
// Remove the unwanted entitlement ID
var filteredEnt = ent.filter(function(id) {
return id !== '5b806c328396c6105fc86770deaad354';
});
if (ritm.cat_item.sys_id == gs.getProperty('hsbc.mobile.new.id')) {
if (corp != 'Corporate' && emaildata == 0) {
gs.log('Filtered entitlements: ' + filteredEnt.join(','));
}
}
entitlementIds = filteredEnt.join(',');
gs.log('Final entitlementIds: ' + entitlementIds);
if (!entitlementIds) return;
this.generateADLDSRequest(ritm, entitlementIds);
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-20-2025 04:38 AM
try this
var entitlementIds = this.getADLDSEntitlement(ritm);
var corp = ritm.variables.corp_or_byod.getValue();
var emaildata = ritm.variables.emaildata.getDisplayValue();
var intunemdm = gs.getProperty('intune.mdm.corp.mobile');
var ent = entitlementIds.split(',');
// Remove the unwanted entitlement ID
var filteredEnt = ent.filter(function(id) {
return id !== '5b806c328396c6105fc86770deaad354';
});
if (ritm.cat_item.sys_id == gs.getProperty('hsbc.mobile.new.id')) {
if (corp != 'Corporate' && emaildata == 0) {
gs.log('Filtered entitlements: ' + filteredEnt.join(','));
}
}
entitlementIds = filteredEnt.join(',');
gs.log('Final entitlementIds: ' + entitlementIds);
if (!entitlementIds) return;
this.generateADLDSRequest(ritm, entitlementIds);
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-20-2025 04:43 AM
Hello @Ankita9793, if you just wish to remove desired entry from 'entitlementIds' then can you please try below code? as I'm not very certain about the functionality you are trying to achieve, you might have to change the order.
// Value to remove
var toRemove = '5b806c328396c6105fc86770deaad354';
// Filter out the unwanted value
ent = ent.filter(id => id !== toRemove);
gs.info(ent);
###################
Below I'm trying to change your code, but you can modify if required
var entitlementIds = this.getADLDSEntitlement(ritm);
var corp = ritm.variables.corp_or_byod.getValue();
var emaildata = ritm.variables.emaildata.getDisplayValue();
var intunemdm = gs.getProperty('intune.mdm.corp.mobile');
var ent = entitlementIds.split(',');
var newent =[];
// ent contains==>> 0678191f1b13a4d06c3c2f007e4bcb9b,5b806c328396c6105fc86770deaad354
if (ritm.cat_item.sys_id == gs.getProperty('hsbc.mobile.new.id')) {
if (corp != 'Corporate' && emaildata == 0) {
gs.log('intune.mdm.corp.mobile catitem corp emaildata' +corp +emaildata +ent);
var index = ent.indexOf(intunemdm); //Infodir-IntuneMobileMDM-Enrollment-CORP
gs.log('intune.mdm.corp.mobile INDEX' +index +intunemdm);
// Value to remove
var toRemove = '5b806c328396c6105fc86770deaad354';
// Filter out the unwanted value
ent = ent.filter(id => id !== toRemove);
gs.log('intune.mdm.corp.mobile entitlements1 newent' +newent.push(ent));
}
}
gs.log('intune.mdm.corp.mobile before ent return' +entitlementIds);
if (!entitlementIds) return;
gs.log('intune.mdm.corp.mobile after ent return' +entitlementIds);
this.generateADLDSRequest(ritm, entitlementIds);
},
Regards,
Nishant