Pre-Import script to set field value before import
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2012 07:22 PM
Hi All,
I was hoping somebody would be able to help.....
How do I update the value of a field for all records in a table via script?
Example: I want to change the 'u_Active' field in the 'u_whatever' table to 'false' for all records in that table.
I know I can do this by both right clicking on the blue title bar of a list and selecting 'Update All' as well as selecting multiple fields with the use of the shift key but would like it in script format so I can run as a pre-import task prior to running a scheduled import.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2012 07:42 PM
Something like this;
var recordsToUpdate = new GlideRecord('u_whatever');
recordsToUpdate.query();
while (recordsToUpdate.next()) {
recordsToUpdate.u_active == 'false';
recordsToUpdate.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2012 08:54 PM
Perfect, Thank you very much Jace!!
(Just in case any other non-developers like me read and want to use the script I did have to update the line to read "recordsToUpdate.u_active = 0;" but I'm guessing that is because my field is configured as true/false as opposed to string).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2012 09:03 PM
Cool. Actually, my code has an error in it. In the while loop I placed == not =. So, if you drop one of the equals it should work.