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-25-2016 06:06 AM
Actually now that I think of this again, it wouldn't make sense to change it to an after since I am aborting the update, agreed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2016 10:41 AM
Hmm…maybe this is the issue:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0539962
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2016 11:55 AM
It could be, however we are trying to use action.setRedirectURL. Could you try doing the abort on the function that calls "verifyDailyTotal"? Try putting a return on that function (verifyDailyTotal) that returns true if under 24 and false if greater or equal 24. So the calling function would have something like the below example if you are in fact calling the verifyDailyTotal from the onBefore function.
function onBefore(current, previous) {
if (!verifyDailyTotal){//equals false
action.setRedirectURL(current.u_weekly_time_entry.u_weekly_timesheet);
current.setAbortAction(true);
}
}
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;
return false;
}else{
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2016 12:19 PM
I took me a little while to circle back to this. I tried your suggestion (with slight modification) and it returns true/false when expected, but still the form does not reload. Here is the latest…any other ideas?
evalHours();
function evalHours(){
verifyHoursIncrement(); //first let's see if the value entered is an increment of .25
//next check if the total for the day across all entries for that day are not > 24
if (verifyDailyTotal()){//equals true
action.setRedirectURL(current.u_weekly_time_entry.u_weekly_timesheet);
current.setAbortAction(true);
}
}
function verifyHoursIncrement(){
var hrs = parseFloat(current.u_hours);
var hrs_int = parseInt(current.u_hours);
var dif = hrs-hrs_int;
var dif_inc = dif/0.25;
//if not an increment of .25 then no need to proceed
if (!(dif_inc==0 || dif_inc==1 || dif_inc==2 || dif_inc==3)){
gs.addErrorMessage("Only increments of .25 are permitted. Please click Save to refresh the totals on this form.");
current.setAbortAction(true);
}
}
function verifyDailyTotal(){
var prev = previous.u_hours;
var total_daily_hours = current.u_hours;
var wte = current.u_weekly_time_entry;
var wts = current.u_weekly_time_entry.u_weekly_timesheet; //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("u_weekly_time_entry", wter.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;
}
}
if (total_daily_hours>24){
current.u_hours = prev;
gs.addErrorMessage("Your update could not be applied because the total number of hours for the day cannot exceed 24. Please click Save to refresh the totals on this form.");
return true;
}
else
return false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2016 08:40 AM
Hi Cynthia,
I tried this on my personal instance and is not working either however if you remove the action.setRedirectURL line the current.setAbortAction(true) should prevent the parent record from being updated.
function evalHours(){
if (!verifyHoursIncrement()){; //first let's see if the value entered is an increment of .25
gs.addErrorMessage("Only increments of .25 are permitted. Please click Save to refresh the totals on this form.");
current.setAbortAction(true);
}else if (verifyDailyTotal()){//next check if the total for the day across all entries for that day are not > 24
current.setAbortAction(true);
}
}