Run business rule after template is applied
This content was last updated in 2017. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2017 08:16 AM
Yes, I read this Run Business rule after template is applied but he/she is not looking to do what I'm looking to do... hence this new post.
I need to detect when a certain template is applied to an Incident form, and then do ... for lack of a better term, stuff to the form (change field values, etc..)
Kinda stuck on how to do this. Do I apply a BR on the Incident table or the sys_template table? Or is this "listener" even handled at the BR level at all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 07:27 AM
I just realized that it's because I made the new field "Read Only". I need it Read Only though so that users can't manually trigger this field. How frustrating this is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 07:33 AM
Ah yes, I'd already replied before I spotted this update.
Yes... this kind of thing can be very frustrating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 07:31 AM
Hi David,
A read-only field can't be populated by applying a template. Templates are applied in the clent and the same rules apply that would otherwise apply to a user updating the fields manually. But you could hide the field with a UI policy if it's empty, and you could have a client script to disable the field once it's populated (to prevent users from populating it manually).
Jamie.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 07:52 AM
Yeah, I added this Client Script (onLoad) on the Incident Table:
function onLoad()
{
// Remove the "Applied Template" field
var flds = $$('DIV').each(function(fld) {
if(fld.id && fld.id.indexOf('u_applied_template') >= 0)
{
fld.hide();
}
});
}
Works great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2017 12:18 PM
Just for sharing purposes, the reason I needed this was because of the way Templates add "Time worked" (time_worked). If you use a Template to put time into a ticket, it rewrites the time_worked field instead of putting the time in the hours/minutes/seconds field(s).
So, here's my onChange script for the new (hidden) field I created:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue.length)
{
var oldTime = document.getElementById('sys_original.incident.time_worked');
if (oldTime)
{
var otv = oldTime.value;
var otvA = otv.split(" ");
var otvA_3 = otvA[1].split(":");
var o_hr = otvA_3[0] ? parseInt(otvA_3[0]).toFixed():0;
var o_min = otvA_3[1] ? parseInt(otvA_3[1]).toFixed():0;
var o_sec = otvA_3[2] ? parseInt(otvA_3[2]).toFixed():0;
var ntvA_3 = g_form.getValue('time_worked').toString().split(":");
var n_hr = ntvA_3[0] ? parseInt(ntvA_3[0]).toFixed():0;
var n_min = ntvA_3[1] ? parseInt(ntvA_3[1]).toFixed():0;
var n_sec = ntvA_3[2] ? parseInt(ntvA_3[2]).toFixed():0;
// Original
if (o_hr < 10) { o_hr = '0' + o_hr.toString(); }
if (o_min < 10) { o_min = '0' + o_min.toString(); }
if (o_sec < 10) { o_sec = '0' + o_sec.toString(); }
// New
if (n_hr < 10) { n_hr = '0' + n_hr.toString(); }
if (n_min < 10) { n_min = '0' + n_min.toString(); }
if (n_sec < 10) { n_sec = '0' + n_sec.toString(); }
var originalTime = "1970-01-01 " + o_hr.toString() + ":" + o_min.toString() + ":" + o_sec.toString();
g_form.setValue('time_worked', originalTime);
var inputs = document.getElementsByTagName('input');
for (var ip = 0; ip < inputs.length; ip++)
{
if (inputs[ip].id && inputs[ip].id.indexOf('tmr_') == 0)
{
if (inputs[ip].id.indexOf('_hour') == inputs[ip].id.length - 5)
inputs[ip].value = n_hr;
if (inputs[ip].id.indexOf('_min') == inputs[ip].id.length - 4)
inputs[ip].value = n_min;
if (inputs[ip].id.indexOf('_sec') == inputs[ip].id.length - 4)
inputs[ip].value = n_sec;
}
}
}
g_form.clearValue('u_applied_template');
}
}
This script keeps the original time_worked values, and adds the template values into the appropriate input boxes.
This is how it should be OOB.