Update background color on form when a user is inactive

Niccole
Tera Expert

Hi all,

 

I have a requirement to make a field on a form a different color.  I have already applied a field style, but that only applies to the list view.  I need the field on the form to be a different color as well.  I've tried a UI Policy and have had zero luck. On Community it appear that I may be able to achieve this via a Client Script, but I don't know if it would be a onLoad or onChange and what the script would need to be to validate if the user is inactive and to set the style of the background to red.

 

Requirements:

Table: cmdb_ci_business_app

Field: it_application_owner

Conditions:

> When the user in this field has Active = False make the field red

 

For my UI Policy Script:

function onCondition() {
var appOwner = $('sys_display.cmdb_ci_business_app.it_application_owner');
appOwner.setStyle({backgroundColor:"red"});
alert("The Application Owner is inactive. Update to an active user.");
}

1 ACCEPTED SOLUTION

Niccole
Tera Expert

Update/Solution: needed to create a Business Rule and Client Script

 

Business Rule:

When: display

Filter: no conditions

Advanced Script:

(function executeRule(current, previous /*null when async*/ ) {

var productOwnerGr = new GlideRecord('sys_user');
productOwnerGr.get(current.getValue('it_application_owner'));

var isProductOwnerActive = false;
if (productOwnerGr.isValidRecord())
isProductOwnerActive = productOwnerGr.getDisplayValue('active') == 'true';

g_scratchpad.isProductOwnerActive = isProductOwnerActive;

})(current, previous);

 

Client Script:

UI Type: All

Type: onLoad

Global: True

Script:

function onLoad() {
var isProductOwnerActive = g_scratchpad.isProductOwnerActive;
if (!isProductOwnerActive)
g_form.getDisplayBox('it_application_owner').style.backgroundColor = '#EB907C';

View solution in original post

1 REPLY 1

Niccole
Tera Expert

Update/Solution: needed to create a Business Rule and Client Script

 

Business Rule:

When: display

Filter: no conditions

Advanced Script:

(function executeRule(current, previous /*null when async*/ ) {

var productOwnerGr = new GlideRecord('sys_user');
productOwnerGr.get(current.getValue('it_application_owner'));

var isProductOwnerActive = false;
if (productOwnerGr.isValidRecord())
isProductOwnerActive = productOwnerGr.getDisplayValue('active') == 'true';

g_scratchpad.isProductOwnerActive = isProductOwnerActive;

})(current, previous);

 

Client Script:

UI Type: All

Type: onLoad

Global: True

Script:

function onLoad() {
var isProductOwnerActive = g_scratchpad.isProductOwnerActive;
if (!isProductOwnerActive)
g_form.getDisplayBox('it_application_owner').style.backgroundColor = '#EB907C';