Display Annotation based on Ticket State?

Ben28
Tera Contributor

Is it possible to hide/show an annotation based on the state of a ticket? When a problem is in RCA state, I want an annotation that tells the problem owner to open the PTASK and enter the RCA there. 

I've created an annotation, and added some HTML:

<span id="rca_annotation">Please click on the Problem Tasks below, and add Root Cause Analysis to RCA PTASK</span>

The created a client script, as below but it didn't work:

function onLoad() {
	// Show annotation if 'state' is 'RCA'. Hide otherwise
	if (g_form.getValue("state") == 'Root Cause Analsys') {
		// Show the annotation
		$('rca_annotation').up().show();
	}
	else {
		// Hide the annotation
		$('rca_annotation').up().hide();
	}
}

 

Also tried this slightly more complicated script, which also didn't work:

function onLoad(control, oldValue, newValue, isLoading, isTemplate) {
	// Get the 'State' reference
	var ps = new GlideRecord('problem');
	ps.addQuery('sys_id', newValue);
	ps.query(showAnnotation);
}

function showAnnotation(ps) {
	if (ps.next()) {
		// Show annotation if state is assess or RCA.
		if ((ps.state == 'Assess') || (ps.state == 'root cause analsys')) {
			// Show the annotation
			$('rca_annotation').up().show();
		}
		else {
			// Hide the annotation
			$('rca_annotation').up().hide();
		}
	}
	else {
		// Hide the annotation
		$('rca_annotation').up().hide();
	}
}

I'm not sure if I should be using the full state name, 'Root Cause Analysis' or the state code, 103?

Any help would be much appreciated!

1 ACCEPTED SOLUTION

I understand. So, when I ask if there a reason you can't or don't want to use showFieldMsg or addInfoMessage...is it that you're not familiar with those options? Typically, we would use a UI policy to handle this requirement.

 

  1. Provide a Short description
  2. If you start in the default view, click "Advanced view" under Related Links
  3. Set your conditions (e.g. State is Root Cause Analysis)
  4. On load and Reverse if false should be checked - if they aren't, check them
  5. Add your script in Execute if true (example below shows both message options):
    function onCondition() {
    	g_form.showFieldMsg('state', 'Please click on the Problem Tasks below, and add Root Cause Analysis to RCA PTASK');
    	g_form.addInfoMessage('Please click on the Problem Tasks below, and add Root Cause Analysis to RCA PTASK')
    }
  6. Add your UI policy actions to hide your fields

View solution in original post

4 REPLIES 4

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @Ben28 - In what context? Is there a reason you can't or don't want to use showFieldMsg or addInfoMessage?

I'm hiding 2 fields when the problem is in RCA state, and want a message/annotation to show, to tell people to click on the PTASK. Then when the problem moves to Fix in Progress, the fields are displayed, and the message should disappear/hide.

I understand. So, when I ask if there a reason you can't or don't want to use showFieldMsg or addInfoMessage...is it that you're not familiar with those options? Typically, we would use a UI policy to handle this requirement.

 

  1. Provide a Short description
  2. If you start in the default view, click "Advanced view" under Related Links
  3. Set your conditions (e.g. State is Root Cause Analysis)
  4. On load and Reverse if false should be checked - if they aren't, check them
  5. Add your script in Execute if true (example below shows both message options):
    function onCondition() {
    	g_form.showFieldMsg('state', 'Please click on the Problem Tasks below, and add Root Cause Analysis to RCA PTASK');
    	g_form.addInfoMessage('Please click on the Problem Tasks below, and add Root Cause Analysis to RCA PTASK')
    }
  6. Add your UI policy actions to hide your fields

Thank you! This is exactly what I was looking for. I spent ages searching for "show text on form" or "hide annotation on field state", and never found anything about showFieldMsg or addInfoMessage. Just set it up as you suggested, and it's working perfectly!