Deleting user/HR profile through an API

Casey4
Tera Contributor

When a new hire gets rescinded in our HR system, we would like to delete/rescind the HR Profile and also the onboarding case lifecycle event. 

 

i know this can be done manually, however, is there an API that the HR system can call and cancel this hire and LCE automatically?

 

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Casey4 ,

 I would not recommend data deletion by API as a best practice solution under any circumstances, as deletion of data using this process will result in anomalies\orphaned relationships and would recommend that you use the API to set the sys_user record inactive and\or locked out, and then use an after BR to clean up assigned roles\groups etc. You could then archive inactive users after X months.

 

If you are still keen to delete, here is a sample script:

//Set query and uncomment gr.deleteMultiple()

var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('sys_created_on', '>', "13-05-2018" );

gr.query();
gs.info("Returned Record" + gr.getRowCount());

// gr.deleteMultiple();

 

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @Casey4 ,

 I would not recommend data deletion by API as a best practice solution under any circumstances, as deletion of data using this process will result in anomalies\orphaned relationships and would recommend that you use the API to set the sys_user record inactive and\or locked out, and then use an after BR to clean up assigned roles\groups etc. You could then archive inactive users after X months.

 

If you are still keen to delete, here is a sample script:

//Set query and uncomment gr.deleteMultiple()

var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('sys_created_on', '>', "13-05-2018" );

gr.query();
gs.info("Returned Record" + gr.getRowCount());

// gr.deleteMultiple();

 

Casey4
Tera Contributor

@Community Alums thanks - can we use the script to inactivate: the challenge here being: how would Servicenow ingest the trigger based on the rescind in another system?