Show/Hide annotations on Incident form based on value from related record

Ben Edwards2
Tera Contributor

Task is to show an Out of Office annotation next to the caller field on the Incident record. This doesn't seem to be working, and if the user has their out of office field set to 'true', the annotation does not show. 

 

1. I have created a custom tick box boolean field on user form. 

Out of office | u_out_of_office

 

2. I have a Script include to get value of the custom field. 

var ooocaller = Class.create();
ooocaller.prototype = Object.extendsObject(AbstractAjaxProcessor, {
      oooCheck:function(){
            var caller = this.getParamenter('sysparm_caller');
            var gr = new GlideRecord("sys_user");
            gr.addQuery("sys_id", caller);
            gr.query();
            if (gr.next()){
                     return gr.u_out_of_office;
           }
      }, 
type: 'ooocaller'
});

 

3. I am running an onChange client script (on caller field) to show/hide annotation based on the callers out of office field value, on the user record.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue === '') {
          return;
     }
     var ga = new GlideAjax('ooocaller');
     ga.addParam('sysparm_name', 'oooCheck');
     ga.addParam('sysparm_caller', newValue);
     ga.getXMLAnswer(getResponse);

     function getResponse(answer) {

          if (answer == 'true') {
               $('ooo_caller').up().show();
          } else {
               $('ooo_caller').up().hide();
          }
}
}

 

 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

In your client script please use the below line:-

 

   if (answer == true) instead of if(answer=='true')

 

If changing the above doe snot work please use the below script:-

 

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

function showBSAnnotation(bs) {
	if (bs.next()) {
		
		if ((bs.u_out_of_office == true) {
			// Show the annotation
			$('ooo_caller').up().show();
		}
		else {
			// Hide the annotation
			$('ooo_caller').up().hide();
		}
	}
	else {
		// Hide the annotation
		$('ooo_caller').up().hide();
	}
}

 

Please mark my answer as correct base on Impact.

View solution in original post

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

In your client script please use the below line:-

 

   if (answer == true) instead of if(answer=='true')

 

If changing the above doe snot work please use the below script:-

 

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

function showBSAnnotation(bs) {
	if (bs.next()) {
		
		if ((bs.u_out_of_office == true) {
			// Show the annotation
			$('ooo_caller').up().show();
		}
		else {
			// Hide the annotation
			$('ooo_caller').up().hide();
		}
	}
	else {
		// Hide the annotation
		$('ooo_caller').up().hide();
	}
}

 

Please mark my answer as correct base on Impact.

Ben Edwards2
Tera Contributor

@Saurav11 Your client script worked well so I used that. Thanks! 🙂