Query to update column data based on a condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 01:52 PM
I want to use something like this below but have some sort of condition as to only update/delete certain columns. I am new at coding so learning as I go.
What I am trying to do is just delete the columnn data from
table x_nu_ea_devices column discovery_source where third_party_id is not null or empty
I am new to writing code so forgive me if I butchered this
var gr = new GlideRecord('u_table');
gr.query();
while(gr.next())
{
gr.u_column='';
gr.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 01:56 PM
Hi,
You want to modify values of some records ?
It would be better if you provide details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 02:47 PM
Added update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2022 02:16 PM
Check this out;
https://thesnowball.co/how-to-use-addencodedquery-with-gliderecord-in-servicenow/
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 12:57 AM
Hi
var grUpdateColumn = new GlideRecord('x_nu_ea_devices');
grUpdateColumn.addNotNullQuery('third_party_id'); //Makes sure the record does not have third party id
grUpdateColumn.query();
while(grUpdateColumn.next())
{
grUpdateColumn.discovery_source =''; //Sets to empty
grUpdateColumn.update();
}
Hope this helps, try this code and let us know if there are any issues and we can try and resolve the issue.
Thanks
-Harneet Sital
Request you to please mark my answer as helpful or correct based on the impact
Find all my ServiceNow articles here