business rule abort action and gr.insert() returns another sys_id

r_gissarl_
Mega Expert

Hi,

In a business rule, I need to cancel an insert on some condition. If the condition is reached, it updates the values of another record. That's ok.

But I need the business rule to return the sys_id of the updated record, is anyone have a solution for this (you can't make a return on BR) ?

Because when the insert is made on other scripts, they get back the sys_id to make some operations on it.

For exemple, this is what I need :

  1. When an insert of new hardware is done from anywhere in the system : ID = new_hw.insert()
  2. If the insert matches the business rules, ID contains the sys_id of the updated record.
  3. If the insert doesn't match the conditions, ID contains the sys_id of the newly created asset.

Regards.

For info, the BR :

var mac_utils = new u_MacUtils();

var result_mac, result;

result_mac = mac_utils.validateMac(current.u_mac_address);

result = mac_utils.already_in_park_even_retired(current.company, current.u_mac_address);

if(result_mac[0] && result[0] == true) {

      var old_hw = new GlideRecord('alm_hardware');

      odl_hw.setWorkflow(false); // in case of the old HW is from another company

      old_hw.get(result[1]);

     

      old_hw.model = current.model;

      old_hw.comments = current.comments;

      old_hw.model_category = current.model_category;

      old_hw.u_related_item = current.u_related_item;

      old_hw.assigned_to = current.assigned_to;

      old_hw.install_status = current.install_status;

      old_hw.location = current.location;

      old_hw.company = current.company;

      old_hw.u_reseller = current.u_reseller;

     

      old_hw.update();

     

      gs.log("+++ Re using an hardware instead of creating a new one for : " + old_hw.assigned_to + " with mac : " + current.u_mac_address);

     

      current.setAbortAction(true);

      //return old_hw.sys_id;

}

6 REPLIES 6

anupama8
Tera Expert

Try printing old_hw.sys_id before aborting the action.



PS: Hit like, Helpful or Correct depending on the impact of the response.


With gs.print ?



from wiki, it should not work : gs.print : Writes a message to the system log. This method does not write the message to the syslog table unless debug has been activated.


gs.addInfoMessage will work in Business Rule. It prints the result on top of the form.



PS: Hit like, Helpful or Correct depending on the impact of the response


Well, I don't want to inform the user that the insert has not been done.



For exemple, this is what I need :


  1. When an insert of new hardware is done from anywhere in the system : ID = new_hw.insert()
  2. If the insert matches the business rules, ID contains the sys_id of the updated record.
  3. If the insert doesn't match the conditions, ID contains the sys_id of the newly created asset.