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-26-2022 06:38 AM
@Harneet Sital
First off let me say thank you for assisting me.
That is close. Let me see if I can put this in a SQL statement. To see if it make more sense
UPDATE x_nu_ea_devices
SET third_party_id is not 'NULL'
WHERE discovery_source ='4'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 09:01 AM
Hi
Perfect, I have tried to break down your query into ServiceNow Gliderecord query and hoping this is what you were after 🙂
var grUpdateColumn = new GlideRecord('x_nu_ea_devices'); // Equivalent query : UPDATE x_nu_ea_devices
grUpdateColumn.addQuery('discovery_source','4'); // Euivalent query : WHERE discovery_source ='4'
grUpdateColumn.query();
while(grUpdateColumn.next())
{
grUpdateColumn.third_party_id=''; // Euivalent query : third_party_id is not 'NULL'
grUpdateColumn.update();
}
Thanks
-Harneet Sital
Would really appreciate it if you could take a few minutes to mark the answer as Correct and Helpful so we can close the thread.
Find all my ServiceNow articles here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 01:45 AM
Hi
Did this work or do you need any further help to close this thread?