Query to update column data based on a condition

Chrisww2
Kilo Contributor

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

7 REPLIES 7

@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'

Hi @Chrisww2 

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

Hi @Chrisww2 

Did this work or do you need any further help to close this thread?