schedule job

si21
Tera Guru

Hi everyone,

We have schedule job which runs everyday to delete HR profiles created for Contingent workers.

Now we have requirement to exclude contingent workers from getting their HR profile removed if they are having

1.sn_hr_core.basic role ( contractors who are agents)

2. 'employeeType' = 'ANC' (this is a field on HR profile table)

How to include above condtions

cleanUpHRProfiles();

function cleanUpHRProfiles(){
	
	// Cleanup all HR profiles where WORKDAY ID is EMPTY
	
	var encodedstr1 = "correlation_idISEMPTY";
		
	var hrObj = new GlideRecord("sn_hr_core_profile");
	hrObj.addEncodedQuery(encodedstr1);
	hrObj.setLimit(1000);
	hrObj.deleteMultiple();
		
}

 suggest me best approach

TIA

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@si21 

use this and give correct value for Employee Type

cleanUpHRProfiles();

function cleanUpHRProfiles() {

    // Cleanup all HR profiles where WORKDAY ID is EMPTY
	
	// form the correct query and paste here
    var encodedstr1 = "user.roles=sn_hr_core.basic^correlation_idISEMPTY^employment_type=contingent";

    var hrObj = new GlideRecord("sn_hr_core_profile");
    hrObj.addEncodedQuery(encodedstr1);
    hrObj.setLimit(1000);
    hrObj.deleteMultiple();

}

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

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@si21 

use this and give correct value for Employee Type

cleanUpHRProfiles();

function cleanUpHRProfiles() {

    // Cleanup all HR profiles where WORKDAY ID is EMPTY
	
	// form the correct query and paste here
    var encodedstr1 = "user.roles=sn_hr_core.basic^correlation_idISEMPTY^employment_type=contingent";

    var hrObj = new GlideRecord("sn_hr_core_profile");
    hrObj.addEncodedQuery(encodedstr1);
    hrObj.setLimit(1000);
    hrObj.deleteMultiple();

}

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