Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Update record from business rule

david_wilhelm
Giga Contributor

I have the following business rule on a table.

function onAfter(current, previous) {

    //This function will be automatically called when this rule is

  var gr = new GlideRecord('u_safety_events');

  gr.get(current.getValue('u_safety_event_number'));

  gr.u_total_cost_confirmed = true;

  gr.update();

This does not update the table. I test the getValue('u_safety_event_number') using ctrl, shift, alt, j and the sys_id returned is correct.

The business rule debugging doesn't shed any light on the issue:

14:03:25.411: Execute after update business rules on u_safety_events_property_loss:SPL0001064 before engines (order <1000)

14:03:25.411: ==> 'Update Total Confirm on parent' on u_safety_events_property_loss:SPL0001064

14:03:25.421: <== 'Update Total Confirm on parent' on u_safety_events_property_loss:SPL0001064

14:03:25.421: Finished executing after update business rules on u_safety_events_property_loss:SPL0001064 before engines (order <1000)

1 ACCEPTED SOLUTION

The business rule works when I run it onBefore instead of onAfter:



function onBefore(current, previous) {


    var intConfirmed;


  if(current.getValue('u_total_cost_confirmed') == 'Yes'){


  intConfirmed = "true";


  }else{


  intConfirmed = "false";


  }




  var gr = new GlideRecord('u_safety_events');


  gr.get(current.getValue('u_safety_event_number'));


  gr.u_total_cost_confirmed = intConfirmed;


  gr.update();


}


View solution in original post

2 REPLIES 2

Mike Allen
Mega Sage

Use current.u_safety_event_number.



I assume u_safety_event_number is a reference field.   get is used with a sys_id or a ('field', 'field_value').   The reference field should be the sys_id, so a plain current.u_safety_event_number should work.


The business rule works when I run it onBefore instead of onAfter:



function onBefore(current, previous) {


    var intConfirmed;


  if(current.getValue('u_total_cost_confirmed') == 'Yes'){


  intConfirmed = "true";


  }else{


  intConfirmed = "false";


  }




  var gr = new GlideRecord('u_safety_events');


  gr.get(current.getValue('u_safety_event_number'));


  gr.u_total_cost_confirmed = intConfirmed;


  gr.update();


}