How to hide Form Annotation until specific field condions are met

Jerri
Mega Contributor

I am trying to add a form annotation that displays only if certain field conditions are met. Can anyone point me in the right direction?

1 ACCEPTED SOLUTION

Change your client script to run 'onChange' against the 'Business service' field.  Then use the script below (adjusting the Business Criticality values to match yours as needed) and you should be good to go.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	// Get the 'Business service' reference
	var bs = new GlideRecord('cmdb_ci_service');
	bs.addQuery('sys_id', newValue);
	bs.query(showBSAnnotation);
}

function showBSAnnotation(bs) {
	if (bs.next()) {
		// Show annotation if high business criticality.
		if ((bs.busines_criticality == '1 - most critical') || (bs.busines_criticality == '2 - somewhat critical')) {
			// Hide the annotation
			$('my_annotation').up().show();
		}
		else {
			// Hide the annotation
			$('my_annotation').up().hide();
		}
	}
	else {
		// Hide the annotation
		$('my_annotation').up().hide();
	}
}

Please mark this response correct if I've answered your question.  Thanks!

View solution in original post

26 REPLIES 26

davis125
Kilo Contributor

I know this is an old thread, but the only way I got this to work in scoped application in the NewYork release is below. This will force the display of the single annotation even if they are toggled off.

1) form annotation: 

<span id="anno1">whatever</span>

2) onload client script:

function onLoad() {

var row = document.getElementsByClassName("annotation-row");
row[0].style.display = 'block';
row[0].parentElement.style.display = 'block';

var wrapper = document.getElementsByClassName("annotation-wrapper");
wrapper[0].style.display = 'block';
wrapper[0].parentElement.style.display = 'block';

var anno1 = document.getElementById("anno1");
anno1.style.display = 'block';
anno1.parentElement.style.display = 'block';

}

Also, make sure you have system property ....glide.script.block.client.globals set to false.

Did you have to add glide.script.block.client.globals as a new system property for your scoped application?