GlideMultipleUpdate with addQuery

Chris P_
Tera Expert

I'm trying to use GlideMultipleUpdate, but it behaves kinda weird...

Here's my code:

var grt = new GlideMultipleUpdate("u_grit_path_import");

grt.addQuery('u_groupname', 'BUILTIN\\Administrators');

//grt.addQuery('u_groupname', 'CONTAINS', 'BUILTIN');

//grt.addQuery('u_groupname', 'IN', 'BUILTIN\\Administrators');

//grt.addQuery('BUILTIN', 'IN', 'u_groupname');

grt.setValue("sys_import_state", 'ignore');

grt.execute();

I've tried with different options which are commented out in the above example, but I keep getting the error message:

*** ERROR *** com.glide.db.GlideSQLException:

See glide log for error details

With the following message in the log:

*** ERROR *** com.glide.db.GlideSQLException:

And when I don't get an error message, he just skips the where-clause and updates all records.

I'm at a loss, any ideas anyone?

1 ACCEPTED SOLUTION
22 REPLIES 22

I did try that variant yes.


var grt = new GlideRecord('u_grit_path_import');


grt.addQuery('u_groupname','CONTAINS','BUILTIN');


grt.query();


while(grt.next())


{


var getImportRow = new GlideRecord('sys_import_set_row');


getImportRow.addQuery('sys_target_table','u_grit_path_import');


getImportRow.addQuery('sys_target_sys_id',grt.getValue('sys_id'));


getImportRow.query();


if(getImportRow.next())


{


getImportRow.sys_import_state='ignored'


getImportRow.update();


}


}



//Note : I am not sure if this is recommended by ServiceNow or not


The reason why you were getting the error was 'sys_import_state' is not present in your import set table but part of your parent table (Import set Row)


Just created a test import table and the screenshot should be self explanatory.



11-12-2015 5-20-03 PM.png


Aaaah since the multipleupdate directly accesses the database a problem occurs with parent-child tables.


That explains it.


Also why on a row-by-row update, using a normal gliderecord, it did work.



So how would the update action look like using GlideMultipleUpdate? Or is it just not possible for parent-child tables?


I have not used GlideMultipleUpdate much. Hence I am unaware of its capabilities. But I do feel that it would not allow dot walking (Parent-child table).



If you see the code above, I have used the sys id from the outer query to get the related record of import set row table. Hence that would work well. But if you are applying this to a huge set of data, I would advise you to bring this into smaller chunks and process it.