
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 02-06-2019 02:57 PM
So usually when you are pulling data from a data source, unless there is an attribute that specifically calls out whether a record is active or inactive, data sources will usually only return active records and inactive records will simply "drop-off".
This called into question how would it be best to go about deactivating records that do not show up from your data source anymore? After a bit of scouring, the only solutions I saw were to create a date field to be populated with the date each record is updated from the data source to then run a scheduled job that would deactivate the record if that date field was past a certain time frame that you would expect it to have been updated.
While this is not at all a bad solution, I wanted it to be just a bit simpler and more maintainable since in this case, I was putting this together for a customer.
What is necessary for this solution is an understanding of how and when each transform script runs. onStart is once before any rows are read, onBefore runs on each row read, onAfter is after each row is transformed, and onComplete is once everything is done.
In this case, the easy solution to this issue is running an onStart script with a GlideRecord to what will be the transform's target table (onStart cant access the target as it runs before any rows are read), adding your query should you need to limit the records you are affecting, and setting active to false on every record that matches this query. This script will essentially allow you to start with a clean slate at the very beginning of your transform so that when you are only returning active records from your data source, all those that do not show up remain inactive.
Hope this helps! Please mark this article as "helpful" if you found it so! See below for an example of this onStart script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var manager = new GlideRecord('sys_user');
manager.addQuery('u_manager', true);
manager.query();
while(manager.next()){
manager.u_manager = false;
manager.update();
}
})(source, map, log, target);
- 761 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Jasmine, I just changed the field names for my use case, but otherwise used the same script as you provided.