- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:18 AM
Just looking for sample code to update a field value on all contact records.
Table: customer_contact
Field: Verification Status (u_verification_status)
Value: Not Verified
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:29 AM
Hi @MStritt,
To update the "Verification Status" field on all contact records in the "customer_contact" table in ServiceNow, you can use the following sample code:
var gr = new GlideRecord('customer_contact');
gr.query();
// Loop through each record and update the field
while (gr.next()) {
gr.setValue('u_verification_status', 'Not Verified');
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:29 AM
Hi @MStritt,
To update the "Verification Status" field on all contact records in the "customer_contact" table in ServiceNow, you can use the following sample code:
var gr = new GlideRecord('customer_contact');
gr.query();
// Loop through each record and update the field
while (gr.next()) {
gr.setValue('u_verification_status', 'Not Verified');
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:33 AM
Thanks! Can you add a line in the code where it only updates a few records? Maybe 10? For testing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 09:50 AM - edited 12-12-2023 09:53 AM
You can use the setLimit() function to set a limit of 10,20, etc records. And the orderBy() function to sort by a particular column.
Here is the revised version of this script:
var gr = new GlideRecord('customer_contact');
gr.orderBy('sys_created_on'); // Order by created date to update the first 10 records
gr.setLimit(10); // Limit the query to the first 10 records
gr.query();
// Loop through each record and update the field
while (gr.next()) {
gr.setValue('u_verification_status', 'Not Verified');
gr.update();
}