- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 05:17 PM
Hi @MBarrott ,
Yes, you can reuse a single GlideRecord instance for multiple operations by clearing its state after each use. Here's how you can do it:
// Declare a single GlideRecord instance
var gr = new GlideRecord('your_table_name');
// Query 1: Insert operation
gr.initialize(); // Clear the GlideRecord state
gr.setValue('field1', 'value1');
gr.setValue('field2', 'value2');
gr.insert();
// Query 2: Delete operation
gr.initialize(); // Clear the GlideRecord state
gr.addQuery('field1', 'value1');
gr.addQuery('field2', 'value2');
gr.deleteMultiple();
// Query 3: Record gathering
gr.initialize(); // Clear the GlideRecord state
gr.addQuery('field3', 'value3');
gr.query();
while (gr.next()) {
// Process each record
}
In this example, `initialize()` method is called on the `gr` instance before each new operation to clear its state. This ensures that the GlideRecord is reset and ready to be used for the next query, insert, or delete operation without declaring multiple GlideRecord instances.
Thanks,
Danish