updateMultiple() Question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 12:26 PM
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.
Regards
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 12:38 PM
Hi Paul,
You need to use async Glideajax to update multiple records from UI action script.
You can call script include from UI action and update multiple records from script include.
Below are examples
Examples of asynchronous GlideAjax
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 12:51 PM
Hi Paul,
If you have the client option clicked, please add the below code in the UI action script after the client script function ends
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
var grupdaterel = new GlideRecord('sys_user_preference');
grupdaterel.addQuery('name','overview_help.visited.helsinki');
grupdaterel.query();
grupdaterel.setValue('value', 'false');
grupdaterel.updateMultiple();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 01:43 PM
Hi Venkat.
Thanks for the reply. Gave that a try still not working, no records getting updated and there are records matchin the name query of 'overview_help.visited.helsinki'
Any ideas?
Action name: release_notes_on
Client: ticked
UI Action Code:
function enable_release() {
if(confirm('Are you sure you want to update he records?')){
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'release_notes_on'); //MUST call the 'Action name' set in this UI Action
}
else{
return false;
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runBusRuleCode();
//Server-side function
function runBusRuleCode(){
var grupdaterel = new GlideRecord('sys_user_preference');
grupdaterel.addQuery('name','overview_help.visited.helsinki');
grupdaterel.query();
grupdaterel.setValue('value', 'false');
grupdaterel.updateMultiple();
action.setRedirectURL(current);
}
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 02:11 PM