Scheduled Flow Action script

Andrew_TND
Mega Sage
Mega Sage

Hello all, this is the first time creating a custom action in UI builder so I dont know whether I've done this wrong.

This runs every morning  and should update information for GDPR reasons if it matches the right conditions.

The test runs fine but when I leave it to run nothing updates.

Anyone point me in the right direction?

(function execute(inputs, outputs) {
  
  var fieldsToUpdate = ['short_description', 'description']; 
  var erategr = new GlideRecord('TABLE'); 
  if (erategr.get(current.sys_id)) { 
    fieldsToUpdate.forEach(function(field) { 
      erategr.setValue(field, "**Data Removed**"); }); 
    erategr.update(); } 
  
  var auditgr = new GlideRecord('sys_audit'); 
  auditgr.addQuery('documentkey', current.sys_id); 
  auditgr.query(); while (auditgr.next()) { 
    auditgr.oldvalue = '**Data Removed**'; 
    auditgr.newvalue = '**Data Removed**'; 
    auditgr.update(); }
  
  var historygr = new GlideRecord('sys_history_line');
  historygr.addQuery('id', current.sys_id); 
  historygr.query(); historygr.deleteMultiple(); 
  
  current.work_notes = 'Data Removed'; 
  current.update();

})(inputs, outputs);

 

3 REPLIES 3

Mark Manders
Mega Patron

What is 'current'? You say it runs scheduled, so how does it know what to update? I am sure you have some logic in there, because otherwise also test wouldn't work, but we don't have that logic here. 

What is the exact requirement? How did you create an action in the ui builder that runs on a schedule? 

Maybe I am missing something, but it sounds to me that a scheduled 'something' should run as a flow or a scheduled job.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark, Thanks for coming back to me.

I figured out what it is. Because I've not inputted any input variables and added that into the script its fallen over.

That figures. And with testing you just give the input in the test. Great that it is resolved!


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark