updateMultiple() Question

Paul Curwen
Giga Sage

Can you use updateMultiple() in a client script?

I ask because I can run the following as a background script and it works fine and takes only a couple of seconds to complete the update of a few thousand records. :

var grupdaterel = new GlideRecord('sys_user_preference');

grupdaterel.addQuery('name','overview_help.visited.helsinki');

grupdaterel.query();

grupdaterel.setValue('value', 'false');

grupdaterel.updateMultiple();

When it runs in a UI Action script, it doesn't work. The UI Action has the Client option ticked and code is running as alerts show when inserted into the code, but only up to the grupdaterel.updateMultiple(); line.

I need to update approx 2000 records regularly when a user clicks a UI Action button on a form. I can get it working using the standard GlideRecord > While loop e.g:

var gr = new GlideRecord('sys_user_preference');

gr.addQuery('name','overview_help.visited.helsinki');

gr.query();

while (gr.next()) {

gr.value = 'false';

gr.update();

}  

but it takes an age to update this many records. Thought updateMultiple() would be ideal but no joy so far.

Thanks in advance.

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul
6 REPLIES 6

Hi Venkat,



Thank for the reply. Glad it works for you, that's why I'm puzzled it's not working for me.



Yes, I've got enable_release() in the onclick and it's running the confirm as expected. When I click OK no records are being updated even though has a have a couple thousand entries in the user_preference table with the value of   overview_help.visited.helsinki. Obviously I'm overlooking the obvious here somewhere.



I've double checked the Action Name is set as release_notes_on to make sure the gsftSubmit line then runs the UI Action server side, but it looks like the server side code just isn't running.



Regards,



Paul.


***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul

Hi Paul,



May be it is to do with the amount of records though i feel it should have worked. You can try an alternatively solution:-


Change the business rule to:


function runBusRuleCode(){


gs.eventQueue("sys_user_preference_help", current);


action.setRedirectURL(current);


}


In the Events -> Registry, add a new event


Create a new event called sys_user_preference_help   and the table to be the table this UI action was added.



In the Events -> Script Action


Then create a new script action (with a suitable name) with event name sys_user_preference_help and in the script code add:



var grupdaterel = new GlideRecord('sys_user_preference');


grupdaterel.addQuery('name','overview_help.visited.helsinki');


grupdaterel.query();



grupdaterel.setValue('value', 'false');


grupdaterel.updateMultiple();




This will be an async call and it will update it with not much user obtrusiveness.