Reloading a form after business rule executes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2016 10:43 PM
I have a question. I am wondering if it is possible to reload a form after a business rule executes.
As an example, if a user attaches a file to a record and a business rule executes that moves that attachment to a new location, can I force the form to refresh so that it no longer shows the attachments that were added to the record?
I am assuming it would be client side, I just am not sure on how to code it.
Thanks!
https://youtube.com/watch?v=zYi8KhP9SUk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 02:07 PM
Thank you for this. I tried but it is still updating the total on the screen even though the value is not committed to the DB.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 02:13 PM
Could you post the code from your business rule here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 02:20 PM
Here it is. You'll see I added the redirect towards the bottom and then commented it out.
function verifyDailyTotal(){
var prev = previous.u_hours;
var total_daily_hours = current.u_hours;
var wte = current.u_weekly_time_entry.sys_id;
var wts = current.u_weekly_time_entry.u_weekly_timesheet.sys_id; //Weekly Timesheet ID
//use the Weekly Timesheet ID to get all the Weekly Time Entries for that timesheet
var wter = new GlideRecord("u_weekly_time_entry");
wter.addQuery("u_weekly_timesheet", wts);
wter.addQuery("sys_id", "!=", wte); //let's not double count the current record we are updating
wter.query();
//for each Weekly Time Entry, go get Daily Time Entry hours for the same day
while (wter.next()) {
var dter = new GlideRecord("u_daily_time_entry");
dter.addQuery("u_worked_on", current.u_worked_on);
dter.addQuery("sys_id", "!=", current.sys_id); //let's not double count the current record we are updating
dter.query();
while (dter.next()) {
total_daily_hours = total_daily_hours + dter.u_hours;
}
}
// //whether updated hours were valid or not, we want to reflect that the timesheet was updated.
// var gr = new GlideRecord("u_weekly_timesheet");
// gr.addQuery("sys_id", current.u_weekly_time_entry.u_weekly_timesheet);
// gr.query();
// if (gr.next()) {
// gr.sys_updated_on=gs.nowDateTime();
// gr.update();
// }
if (total_daily_hours>24){
gs.addErrorMessage("Your update could not be applied because the total number of hours for the day cannot exceed 24. Please click Save to reload this form.");
//current.u_hours = prev;
//action.setRedirectURL(current.u_weekly_time_entry.u_weekly_timesheet);
current.setAbortAction(true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 03:27 PM
Thanks, I don't see why it wouldn't work. Is this a before or an after business rule? I'm assuming it's a before because I don't see the current.update(). Here I'm doing something similar. My business rule is a before insert/update:
function onBefore(current, previous) {
var amtFound = false;
var item = current.u_expense_item;
var itemAmt = 0;
var restrict = current.u_expense_item.u_restrict;
var expense = new GlideRecord('u_travel_and_expense');
if (expense.get(current.parent.parent)){
var location = expense.u_expense_location;
var cat_item = new GlideRecord('u_expense_cat_items_amounts');
cat_item.addEncodedQuery('u_expense_item.sys_id='+ item +'^u_location.sys_id='+location);
cat_item.query();
while (cat_item.next()){
itemAmt = cat_item.u_allowed_amount;
amtFound = true;
}
}
if (current.u_total > itemAmt && amtFound){
if (restrict){
gs.addErrorMessage('Please enter an amount up to ' + itemAmt);
current.setAbortAction(true);
}else if (current.u_business_purposes == ''){
gs.addErrorMessage('You exceeded the allowed amount of '+ itemAmt +' ,describe the reason for the excess on the Business Purposes field');
current.setAbortAction(true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 04:07 PM
It's a before. I could try changing it to an after and add the update statement. I'll give that a shot in the morning and let you know how it goes. Thanks for looking out it.