How to delete/deactivate record with transform map?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2021 02:14 AM
I have to import a file with association to user and one group.
When a user is no loger in the the file it must be removed from the servicenow group.
How can I make this with a transform map?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2021 02:35 AM
Hi
you cannot delete any record by using transform map you have to remove user manually from that group
Thanks,
Rakesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2021 03:11 AM
Hi
OOTB there is no such option with Transform Maps but you can have a way to implement deletion/deactivation. What you can do is:
- Create a onStart Transform Script and initialize an array type variable.
function onStart(<parameters>) { //Use onStart constructor as provided OOTB var userArr = []; //Array will be populated on onAfter Transform Scripts }​
- Then create onAfter Transform Script and in that transform Script check the status of import if it is successful then push the target record sys_id in the array "userArr"
- Finally write a onComplete Transform Script and do a GlideRecord query on User table:
function onComplete( < parameters > ) { //Use the OOTB constructor var deactivateUserGr = new GlideRecord('sys_user'); deactivateUserGr.addEncodedQuery('sys_idNOT IN' + userArr.join(',')); deactivateUserGr.query(); while (deactivateUserGr.next()) { deactivateUserGr.active = false; deactivateUserGr.update(); //OR //deactivateUserGr.deleteRecord(); } }​
Please try the above steps and see if it works for you.
If my answer is helpful then please do mark my reply as correct/helpful.
Regards,
Kartik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-17-2022 03:06 PM
Hi Kartik,
I would like to try to use your solution. However, I am very script-saavy yet. Can you provide an example script or screenshot for step #2? Please and thank you in advance!
-Cyn

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2021 03:22 AM
Hi Alberto,
My suggestion would be,
1. Create an active field on the target table
2. Create a onBefore transform script to set the active attribute to false on all records
3. During transformation,when record is being updated, set the active attribute to true
4. After completing the transform, you can either write an onComplete transform script or a scheduled job to delete the inactive records that have not been touched during the transform.
Please mark my answer as Correct & Helpful, if applicable.
Thanks
Sandeep