If '5b806c328396c6105fc86770deaad354' found then remove 5b806c328396c6105fc8677 from the variable.

Ankita9793
Tera Contributor

 

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 

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);
               
                for (var i =0; i<=ent.length; i++){

                if (index != -1) {

                    gs.log('intune.mdm.corp.mobile found' +ent.length);

                    entitlementIds = ent.splice(index, 1);
                   
                } }
                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);
    },
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nishant8
Giga Sage

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