Table of Contents

Client Scripts

Variable Field read_only FALSE

g_form.setReadOnly('short_title', false);

Incident

Assigned to/Assignment group change

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
       return;
    }
 
    //Type appropriate comment here, and begin script below
     if (newValue != oldValue) {
             g_form.setMandatory("assigned_to",false);
         }  
 }

Hightlight Caller

function onChange(control, oldValue, newValue, isLoading) {
	var callerLabel = $('label.incident.caller_id');
	var callerField = $('sys_display.incident.caller_id');
	if (!callerLabel || !callerField)
		return;
	
	if (!newValue) {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
		return;
	}
	g_form.getReference('caller_id', vipCallerCallback);
}

function vipCallerCallback(caller) {
	var callerLabel = $('label.incident.caller_id').down('label');
	var callerField = $('sys_display.incident.caller_id');
	if (!callerLabel || !callerField)
		return;
	
	// define VIP flag position
	var bgPosition = "95% 55%";
	//If VIP and authorized security requester, set flag and mark purple
	if ((caller.vip == 'true') && (caller.u_authorized_security_requester == 'true')) {
		if (document.documentElement.getAttribute('data-doctype') == 'true')
			bgPosition = "5% 45%";
			
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "purple"});
	}
	// If only VIP, set flag and mark red
	else if (caller.vip == 'true') {
		if (document.documentElement.getAttribute('data-doctype') == 'true')
			bgPosition = "5% 45%";
			
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "red"});
	}
	// If provider and authorized security requester, mark purple
	else if ((caller.u_snow_providers_group_member == 'true') && (caller.u_authorized_security_requester == 'true')) {
		callerField.setStyle({color: "purple"});
	}
	// If only provider, mark red
	else if (caller.u_snow_providers_group_member == 'true') {
		callerField.setStyle({color: "red"});
	}
	//check for Authorized Security Request status, and make sure they're not VIP
	//VIP supercedes ASR
	else if ((caller.u_authorized_security_requester == 'true')&&(caller.vip == 'false')&&(caller.u_snow_providers_group_member == 'false')) {
		callerField.setStyle({color: "blue"});
	} 
	else {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
	}
}

onChange Caller Email is Empty

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
       return;
    }
 
     var callerDetails = g_form.getReference('caller_id',emptyCallerEmail);
     
     function emptyCallerEmail(callerDetails) {
         if (callerDetails.email == '') {
             g_form.clearMessages();
             g_form.addInfoMessage('Please note: Email address for the caller, '+callerDetails.name+', is empty. They will not receive email communications sent by ServiceNow.');
         } else {
             g_form.clearMessages();
         }
     }
    
 }

onLoad Caller Email is Empty

function onLoad() {
    //Type appropriate comment here, and begin script below
     var callerDetails = g_form.getReference('caller_id',emptyCallerEmail);
     
     function emptyCallerEmail(callerDetails) {
         if (callerDetails.email == '') {
             g_form.addInfoMessage('Please note: Email address for the caller, '+callerDetails.name+', is empty. They will not receive email communications sent by ServiceNow.');
         }
     }
 }

Sys_User

Example

function onChange(control, oldValue, newValue, isLoading) {
	var callerLabel = $('label.incident.caller_id');
	var callerField = $('sys_display.incident.caller_id');
	if (!callerLabel || !callerField)
		return;
	
	if (!newValue) {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
		return;
	}
	g_form.getReference('caller_id', vipCallerCallback);
}

function vipCallerCallback(caller) {
	var callerLabel = $('label.incident.caller_id').down('label');
	var callerField = $('sys_display.incident.caller_id');
	if (!callerLabel || !callerField)
		return;
	
    //check for VIP & WFH status
    var bgPosition = "95% 55%";
    if (document.documentElement.getAttribute('data-doctype') == 'true') {
        bgPosition = "5% 45%";
    }

    if (caller.vip == 'true') {
		callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "red"});
	} else if (caller.u_wfh == 'true') {
		callerLabel.setStyle({backgroundImage: "url(images/icons/ico_home.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
		callerField.setStyle({color: "orange"});
	} else {
		callerLabel.setStyle({backgroundImage: ""});
		callerField.setStyle({color: ""});
	}
}

Tasks

Hide empty variables

function onLoad() {
    //Hide all empty variables using the scratchpad object passed from 'Hide Empty Variables' business rule
    if(g_scratchpad.emptyVars != ''){
       var emptyVars = g_scratchpad.emptyVars.split(',');
       for(i = 0; i < emptyVars.length; i++){
          g_form.setDisplay('variables.' + emptyVars[i], false);
       }
    }
 }