business rule on List Edit and Form Edit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2016 12:49 AM
Hi folks,
I'd like to get your expertise in a business rule on List Edit view issue, I have experienced an issue where in ListView (cell update action) the associated table that does not refresh itself, but works on form update, Let me explain further,
HR is a table based on task where Manual SLA Date is a custom date/time field, when Manual SLA date has a value (a date/time), it fires off a After business rule 'Run SLAs'. This works perfectly in the HR Form View when a SLA date is entered, and update the record. The SLA (task_sla which is a associated table with task) lists gets updated (one to many),
However, this SLA list does not get updated when the SLA date is changed in HR List View. In order to troubleshoot whether relevant business rules are fired off (particular after ones) I added a OR condition in the relevant rules current.u_manual_sla_date.changes()
Digging into further with screenshot illustrations,
In HR form, before the Manual SLA is entered
Initial SLA state
Set a Manual SLA Date, and save record
SLA refreshes/updates as expected, the initial SLA got cancelled, and the new one created,
This update, however, does not apply to List View (see below while entering the Manual SLA Date, and hit the green tick, which fires off business rules before/after (Run Task SLAs)
According the sys_log, the Run SLAs BR has been triggered
and yet, checking the SLA status in the form,
The old one got cancelled, which is correct, but the new SLA is not.
The ListView editing and form view edit somehow behave a bit different despite the exact the same field update, and not sure if some BRs only apply to form view (I may be wrong), but have not be been able to find the cause.
Any advice would be appreciated.
Kind regards
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2016 05:54 PM
Hi George,
Could it be a refresh problem? . Have you tried using a redirect within the business rule?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2016 07:52 PM
Hi Berny, Thanks a lot for your attention. Not really, when trying to refresh the task sla tab, no new SLA gets created.
May I ask what 'redirect' mean? Business rule calling business rule?
Thanks,
George
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 07:32 PM
Hi George, I just read a little bit more carefully your post and I believe the problem could actually be something different.
Would you it be possible if I could login into your instance to take a look to the business rule and how it behaves?
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2016 07:02 PM
Hi Berny, Thanks for willing for help further. I have actually found a way to address this issue, which is adding a new Client Script on Cell Edit to fires of the refresh of the SLA calculations. The client script initialises a GlideAjax object, passing a few parameters sys_id, date1, date2, and table,
On the server side, it accepts the parameters and calculate the new SLAs, here is the code that worked
function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
if (table == 'hr' || table == 'u_finance') {
var saveAndClose = true;
//Type appropriate comment here, and begin script below
for (var i = 0 ; i < sysIDs.length; i++) {
var DateOpened;
var grTask = new GlideRecord(table);
grTask.addQuery('sys_id', sysIDs[i]);
grTask.query();
if (grTask.next()) DateOpened = grTask.opened_at;
var DateOpened_MSG = DateOpened.split(' ')[0] + ' 17:00:00'; //Manual SLA starts from 5pm on the date opened
var DateManual = newValue;
var remoteDateCheck = new GlideAjax('QSS_ClientDateTimeUtils');
remoteDateCheck.addParam('sysparm_name','updateTaskManualSLADuration');
remoteDateCheck.addParam('sysparm_date1', DateOpened_MSG);
remoteDateCheck.addParam('sysparm_date2', DateManual);
remoteDateCheck.addParam('sysparm_sysid', sysIDs[i]);
remoteDateCheck.addParam('sysparm_table', table);
remoteDateCheck.addParam('sysparm_dt_type', 'day'); //return type
//remoteDateCheck.addParam('sysparm_include_schedule', 'true'); //calculate based on default schedule (exclude bus days)
remoteDateCheck.getXML(processCdtuResponse);
}
callback(saveAndClose);
} else {
alert ('List editing on Manual SLA Date is not supported in this build (' + table + ')');
callback(false);
}
}
function processCdtuResponse(response){
var days = response.responseXML.documentElement.getAttribute('answer');
days = Math.round(parseFloat(days, 10));
// The SLA can't be less than 1 day.
if(days<1){
alert ('Please choose a date after '+DateOpened_MSG+'.');
}else{ //The SLA can't be more than 730 days in the future (as there are only 365 manual sla definitions)
if(days>731){
alert('SLA duration should be less than 730 days after ' + DateOpened_MSG + '.');
}else{ // You have a valid value, hide the message and set the manual sla duration and start date.
alert ('DateOpened_MSG=' + DateOpened_MSG);
}
}
}
There are comments in the code (sorry not every line has one) but I hope it would provide sufficient clues on how it worked.
Your attention is much appreciated.
Kind regards,