Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Fix script to update field value

MStritt
Tera Guru

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

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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();
}

View solution in original post

5 REPLIES 5

Danish Bhairag2
Tera Sage

Hi @MStritt ,

 

// Define the new value for the Verification Status field

var newValue = 'Not Verified';

 

// Create a new GlideRecord for the customer_contact table

var contactGr = new GlideRecord('customer_contact');

 

// Add a query to target all records (optional if you want to filter specific records)

// contactGr.addQuery('your_condition_field', 'your_condition_value'); // Uncomment and customize as needed

 

contactGr.query();

 

// Loop through the records and update the Verification Status field

while (contactGr.next()) {

    contactGr.u_verification_status = newValue;

    contactGr.update();

}

 

gs.info('Verification Status updated on all contact recordsto: ' + newValue);

 

Thanks,

Danish