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

And are these the actual values of those choices or just the labels?  Can you right-click the 'Business criticality' field label on the Business Service table and select 'Show choice list' to confirm?  We need the actual values, not the labels.

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!

Hi Mark,

Thanks for this script and posts, this is what I was looking to for, however I cannot get it to work.... help

I want the annotation to appear if Assignment group is null.  With the Isolated script unchecked, the annotation stays on the screen regardless of the value in assignment group, with the Isolated Script is checked, I get the following message.

 

What am I doing wrong?

find_real_file.png

 

 

Here is my script 

	if (g_form.getValue('assignment_group') == null ) {
		// Hide the annotation
		$('my_annotation').up().hide();
	}
	else {
		// Show the annotation
		$('my_annotation').up().show();
	}

 

 

I used your above script, but I got the error:.  I am in Madrid 

find_real_file.png

Hi there,

 

Is it possible to amend this script to control the display of multiple annotations, rather than having to write separate scripts for each annotation?

 

Thanks

Steph