GlideRecord deleteRecord() won't delete the record

stephenrpower
Giga Contributor

I'm trying to remove from SN bad records loaded previously from Workday. For example, if someone is hired in error and then that hire is rescinded, I want to remove the EE from ServiceNow. I can tell it's a rescinded hire because the Workday Web Services response returns an empty Original_Hire_Date. So I put the following in the User table Transform Map's onStart:

    var stagingGR = new GlideRecord('sn_hr_integrations_worker_profile');
    stagingGR.addQuery('sys_import_state', 'pending');
    stagingGR.addNullQuery('u_original_hire_date');
    stagingGR.query();

    while (stagingGR.next()) {
        debug("Staging table record " + stagingGR.sys_id + " for worker " + stagingGR.u_worker_id);
        var userGR = new GlideRecord('sys_user');
        userGR.addQuery('user_name', stagingGR.u_worker_id);
        userGR.query();
        while (userGR.next()) {
            debug("User record: " + userGR.sys_id + " for user: " + userGR.user_name + ", " + userGR.name);
            debug("Can delete? " + userGR.canDelete());
            //var deleted = userGR.deleteRecord();
            debug("Deleted? " + userGR.deleteRecord());
            if (userGR)
                debug("Record is still there. Delete failed.");
            else debug("Worker with userID " + stagingGR.u_worker_id + " has no original hire date so I deleted their record from SN.");
        }
    }

 

(debug is just a helper function that prepends a timestamp in milliseconds to the log entry.)

In the App Log, I see:

2020-03-09 17:14:41
13m ago
Information [1583788481790] Staging table record d5a1d2881bab041400af33fccd4bcbaa for worker 123456
2020-03-09 17:14:41
13m ago
Information [1583788481798] User record: f6a8ef5a1b5bc8d000af33fccd4bcb4d for user: 123456, John Doe
2020-03-09 17:14:41
13m ago
Information [1583788481800] Can delete? true
2020-03-09 17:14:41
13m ago
Information [1583788481803] Deleted? false
2020-03-09 17:14:41
13m ago
Information [1583788481806] Record is still there. Delete failed.

What am I missing?

  • The record is found and I'm allowed to delete it (since sys_user.user_name is a coalesce field, I tried it with userGR.get() before resorting to while (userGR.next()) and the result is the same).
  • There's no error thrown when I try to delete (I previously put all of the userGR logic into a try{} block but no error was ever caught).
  • The record is still there.

Any ideas why?

Thanks in advance!

6 REPLIES 6

Christian Prob2
Tera Guru

This is just a hunch so take it with a big whatever: 

I had problems with records generated in different application scopes and then was not able to delete them.

- in which scope is your import happening?

- have you checked if the import generates weird "Restricted Caller Access Privileges" entries (in status "Requested")?

Thanks Christian,

I think you may be on to something but I can't tell for sure, either. This is all running in Human Resources - Integrations. When I look at any updates in Record History, the changed values all indicate they were updated by system, so I don't think it's an access issue. But it certainly could be a cross-scope challenge. Problem is, I can't really isolate it from HR - Int because I'm relying on SN's HR Int code to get the data from Workday into the staging table and transform it from there.

I also wonder if it's related to referencing records. Deleting a user also deletes their HR Prof and Notification Device. But the Reference Cascade Rule on sn_core_hr_profile.user is already set to delete, which should propagate the deletion downstream from sys_user. And I can delete Users and cascade those deletions fine from the UI.

I will check out any caller access privilege entries and post back if I find anything interesting there.

Worst case, I can delete the records in question from the Staging Table so at least no updates propagate via the Transform Map. But I'll still have to manually delete the offending user records.