Use the setWorkflow(false) method on your GlideRecord object to bypass business rules and scripts when inserting or updating records. This is essential when you need to perform bulk data operations without triggering unnecessary system overhead or validation logic.
For example, if you are migrating thousands of user records from an external database, calling this method ensures that only the raw data insertion happens. Without it, every single record would trigger complex server-side checks, causing your script to run significantly slower and potentially hit execution limits.
Why Bypass Workflow Logic?
The primary reason developers use secure GlideRecord methods is to optimize performance during heavy data loads. When a standard insert or update occurs, ServiceNow executes a chain of events. These include before and after scripts, workflow actions, email notifications, and audit logging. If you are processing hundreds or thousands of rows, this chain multiplies the workload on the server.
Bypassing these rules allows the database to write changes directly. This reduces the time required for the operation and lowers the risk of hitting platform limits. It is particularly useful for background jobs, scheduled imports, or one-time data cleanup tasks where immediate consistency checks are not required.
When Is It Safe to Skip Rules?
You should only bypass workflow logic when you are certain that the data being written is already valid. If you skip validation, you might accidentally save incomplete or incorrect information to the database. Always ensure your input data meets all necessary criteria before turning off the safety nets.
This approach is best suited for scenarios where:
- You are performing a large-scale data migration.
- You are archiving old records that do not require active workflows.
- You are updating internal fields that do not affect user-facing processes.
Glide Record Secure vs Standard Insert
It is common to confuse the standard insert method with the secure variant. The difference lies in how they handle the application layer. A standard insert triggers the full suite of business rules. A secure insert skips them entirely.
Think of the standard method as a fully staffed checkout line where every item is scanned and verified. The secure method is like a direct loading dock where items are moved straight into inventory. Both result in the item being stored, but the process and speed differ greatly.
Performance Implications
Using the standard method for bulk operations can lead to timeout errors. The server may stop responding if the number of triggered scripts exceeds the allowed threshold. By using the secure method, you reduce the computational load per row. This keeps your scripts running smoothly even with large datasets.
However, this speed comes with a trade-off. You lose the automatic benefits of business rules. For instance, if you have a rule that automatically assigns a category based on a description, skipping the rule means that field will remain empty. You must manually handle such logic if it is critical for your data integrity.
How to Implement the Method
To use this feature, you first create a GlideRecord instance for the target table. Then, you call the setWorkflow method with a false argument before performing your insert or update. Finally, you execute the action as usual.
Here is the general structure you would follow:
- Create the GlideRecord object for your specific table.
- Call
setWorkflow(false)on that object. - Set the values for the fields you want to update.
- Call
insert()orupdate().
This sequence ensures that the subsequent write operation respects your decision to bypass the workflow engine. Remember to reset the workflow setting if you plan to perform other operations afterward that do require standard processing.
Code Example
var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0010010');
gr.query();
if (gr.next()) {
gr.setWorkflow(false);
gr.description = 'Updated via secure script';
gr.update();
}
In this example, the description field is updated without triggering any incident management scripts. The change is saved directly to the database. This is efficient for simple field updates during maintenance windows.
Common Misconceptions About Security
A frequent misunderstanding is that “secure” implies enhanced data protection or encryption. This is not the case. The term refers to the security of the system’s performance and stability, not the confidentiality of the data. Using this method does not make your data more secure against external threats.
Another misconception is that it disables all checks. While it disables business rules, it does not disable database constraints. Fields marked as mandatory will still reject null values. Required format validations, such as date formats, will still be enforced by the database layer itself.
What Gets Disabled Exactly?
Only server-side business rules and workflows are affected. Client scripts do not run because there is no client interaction in a backend script. Email notifications are suppressed because they are typically tied to workflow actions. Audit logs may still be created depending on your platform configuration, so check your specific instance settings.
Best Practices for Bulk Updates
When performing bulk operations, always test with a small subset of data first. This helps you verify that the bypassed rules were not critical for data integrity. Check the results carefully to ensure no unexpected side effects occurred.
Limit the scope of your queries. Use specific filters to target only the records that need updating. Avoid scanning entire tables unless absolutely necessary. This reduces the memory footprint of your script and prevents potential system slowdowns for other users.
Handling Errors Gracefully
Even with workflow bypassed, database errors can still occur. Wrap your update logic in a try-catch block to handle exceptions properly. Log any failures so you can investigate them later. This ensures that a single bad record does not crash your entire batch job.
If a record fails to update, decide whether to skip it or retry it. Skipping is usually safer for bulk jobs to maintain progress. Retrying can lead to infinite loops if the underlying issue is not resolved. Clear logging helps you identify patterns in failed records.
Alternatives to Consider
If you need some rules to run but not others, consider using scriptable business rules instead of bypassing everything. Scriptable rules give you granular control over which logic executes. You can write custom code to replicate the behavior you need without losing all automation.
For very large datasets, look into import sets and transform maps. These tools are designed specifically for high-volume data loading. They handle batching and error handling automatically. This is often a more robust solution than writing custom GlideRecord scripts.
When to Stick to Standard Methods
Always use the standard method for interactive user actions. When a user clicks a button to create a record, they expect immediate feedback and proper workflow initiation. Bypassing rules in this context leads to a confusing user experience. Data might appear incomplete or unassigned.
Reserve the secure method for backend processes. Background scripts, scheduled jobs, and integration endpoints are the appropriate homes for this technique. Keeping your user-facing logic intact maintains system reliability and predictability.