Hiding fields with a business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 12:13 PM
Hi all,
I have a requirement to track time worked on incidents for our help desk agents only. I would like to hide the time worked field when the incident is not assigned to the help desk. A UI policy could easily do this, but then the time worked while adding notes and reassigning wont be saved.
Is there a way to hide a field in an "after" business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 12:20 PM
I don ´t think you can manipulate a field availability / visibility from a business rule that runs in the server side - it doesn ´t make sense.
What makes sense is to think about this requirement in the other way around, and maybe I can give you some insights:
- Business Rule to add working time into the time worked field when comments, notes, assigned_to, assignment_group etc is changed
- Change the UI Action of save/update in order to add to the current time worked field the time worked you wish to add
Etc, all I am saying is that you need to think in another way to add this time worked into the hidden field instead.
I hope it helps you out.
Best regards,
Felipe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2014 12:21 PM
I have it based off a role and script
If the group is to use Time Worked, it has a new role added
On the forms, I have a client script (needs to have updated visible at the bottom of the form, but is hidden quickly)
It looks to see if the user has the role and if so, makes the "Time Worked" field visible
I also do another check, so if the last update was within a minute, it is visible and NOT mandatory
If the last update was more than a minute ago, it is visible AND mandatory
If the user does not have the role, the field is not visible at all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2014 06:17 AM
This is the most useful suggestion I've heard so far. Thanks, Julian.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2014 07:04 AM
I can't remember if the 2 Ajax includes are OOB or added via routines I have seen on here
function onLoad() {
// Get the last updated on and then hide
var lsu = g_form.getValue('sys_updated_on');
g_form.setVisible('sys_updated_on',false);
// get the now date and time
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name','nowDateTime');
ajax.getXMLWait();
var rightnow = ajax.getAnswer()
//get date difference in seconds
var ajaxdc = new GlideAjax('ClientDateTimeUtils');
ajaxdc.addParam('sysparm_name','getNowDateTimeDiff');
ajaxdc.addParam('sysparm_fdt',lsu);
ajaxdc.addParam('sysparm_difftype','second');
ajaxdc.getXMLWait();
var answer = ajaxdc.getAnswer();
// Make time worked visible and/or mandatory
if(g_user.hasRole('TimeMandatory') && answer < -60 )
{
g_form.setVisible('u_time_worked',true);
g_form.setValue('u_time_worked','');
g_form.setMandatory('u_time_worked',true);
}
else if(g_user.hasRole('TimeMandatory') && answer > -60)
{
g_form.setVisible('u_time_worked',true);
g_form.setValue('u_time_worked','');
g_form.setMandatory('u_time_worked',false);
}
else
{
g_form.setVisible('u_time_worked',false);
g_form.setMandatory('u_time_worked',false);
}
}