business rule abort action and gr.insert() returns another sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 01:32 AM
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 :
- When an insert of new hardware is done from anywhere in the system : ID = new_hw.insert()
- If the insert matches the business rules, ID contains the sys_id of the updated record.
- 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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 01:51 AM
Try printing old_hw.sys_id before aborting the action.
PS: Hit like, Helpful or Correct depending on the impact of the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 01:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 02:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2016 02:22 AM
Well, I don't want to inform the user that the insert has not been done.
For exemple, this is what I need :
- When an insert of new hardware is done from anywhere in the system : ID = new_hw.insert()
- If the insert matches the business rules, ID contains the sys_id of the updated record.
- If the insert doesn't match the conditions, ID contains the sys_id of the newly created asset.