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

sachin_namjoshi
Kilo Patron
Kilo Patron

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


venkatiyer1
Giga Guru

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


}


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


}


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

Regards

Paul

venkatiyer1
Giga Guru

Hi Paul,



The exact code is working for me with no difference and updates the value as well. Just a question, do you get the prompt, have you added the enable_release() in the enable_release() in onclick. Have attached a screenshot of the same



find_real_file.png