Field Message does not display in SOW

Justin Scheich
Tera Guru

I have a functional client script that shows the field message in the classic UI for the SOW view. However, it does not show in the workspace. What am I missing here?

 

function onLoad() {
	//Don't waste an ajax call if the caller is empty
	if (g_form.getDisplayBox('caller_id').value == '')
		return;
	
	//If we're closed, don't query
	if (g_form.getValue('state') == 7)
		return;
	
	var ga = new GlideAjax('LCGIncCheck');	
	ga.addParam('sysparm_name', 'getCallerIncidents');
	ga.addParam('sysparm_caller', g_form.getValue('caller_id'));
	ga.addParam('sysparm_num', g_form.getValue('number'));
	jslog("Calling LCGIncCheck for caller...");
	ga.getXML(doAlertCaller);
}

function doAlertCaller(response) {
	var answer = response.responseXML.documentElement.getAttribute("answer");
	
	jslog("LCGIncCheck for caller answer is: " + answer);

	if (answer != '' || answer != null) {
		g_form.showFieldMsg('caller_id', answer, 'error',true);
	} else g_form.hideFieldMsg('caller_id', true);
}

 

1 ACCEPTED SOLUTION

Justin Scheich
Tera Guru

I was able to find the solution; The script included does work without a change. It would appear that 

if (g_form.getDisplayBox('caller_id').value == '')

is not supported in the workspace and instead needs to be. 

if (g_form.getValue('caller_id') == '')

 

View solution in original post

6 REPLIES 6

HIROSHI SATOH
Mega Sage

In the workspace UI, you'll need to use the form object from the GlideForm API instead of g_form. Additionally, to display messages, you should use the showFieldMsg() method on the form object.

Here's an updated version of your script for the workspace UI:

 

I hope this helps

 

function onLoad() {
    var form = new GlideForm(); // Get the form object for workspace

    // Don't waste an ajax call if the caller is empty
    if (form.getValue('caller_id') == '') return;

    // If we're closed, don't query
    if (form.getValue('state') == 7) return;

    var ga = new GlideAjax('LCGIncCheck');
    ga.addParam('sysparm_name', 'getCallerIncidents');
    ga.addParam('sysparm_caller', form.getValue('caller_id'));
    ga.addParam('sysparm_num', form.getValue('number'));
    jslog("Calling LCGIncCheck for caller...");
    ga.getXML(doAlertCaller);
}

function doAlertCaller(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    
    jslog("LCGIncCheck for caller answer is: " + answer);

    var form = new GlideForm(); // Get the form object for workspace
    if (answer && answer !== '') {
        form.showFieldMsg('caller_id', answer, 'error');
    } else {
        form.hideFieldMsg('caller_id');
    }
}

 

 

Note: GlideForm is a placeholder. The actual method to get the form object in the workspace UI might be different based on the context. Check the workspace documentation or the specific APIs available for your workspace.

 

Robbie
Kilo Patron
Kilo Patron

Hi @Justin Scheich,

 

My very first check would be to ensure that the Client Script field - UI Type is set to 'All'.

If it's set to 'Desktop' - it will not display on the Workspace (I know).

 

Without sight of the Script Include, it's hard to fully test, however I suggest you strip the script back to see where the issue is.

For example, just try and display a message on both the classic back-end view and ensure it displays on the Workspace (SOW) first.

I can absolutely confirm that g_form.showFieldMsg() definitely works and displays a message on both the back-end and SOW Workspace view.

This would suggest something isn't quite working with your 'answer' parameter and causing it to fail. However, of course I can't confirm without the Script Include ; )

 

Try using this same Client Script to test the theory - I've provide a simple onChange Client Script for you to test with on the Incident form and a quick change of the 'Impact' field.

 

Screenshot 2024-08-09 at 17.01.38.png

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(newValue == 1){
		g_form.clearMessages();
		g_form.showFieldMsg('impact', 'Test Msg', 'error', true);
	}
}

 

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

 

Thanks for the reply, 
If I use only the g_form.showfieldMSG alone it does show on the workspace, so it must be an issue with the script include. 
I did confirm the include is available to all application scopes. 

 

var LCGIncCheck = Class.create();
 
LCGIncCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	getLocationIncidents: function() {
		return this._query(this.getParameter('sysparm_loc'), this.getParameter('sysparm_num'), 'location');
	},
	
	getCallerIncidents: function() {
		return this._query(this.getParameter('sysparm_caller'), this.getParameter('sysparm_num'), 'caller_id');
	},
	
	getLocationSharedServices: function() {
		return this._querySharedServices(this.getParameter('sysparm_loc'), this.getParameter('sysparm_num'), 'location');
	},
	
	getEmployeeSharedServices: function() {
		return this._querySharedServices(this.getParameter('sysparm_caller'), this.getParameter('sysparm_num'), 'u_employee_name');
	},
	
	getCallerSharedServices: function() {
		return this._querySharedServices(this.getParameter('sysparm_caller'), this.getParameter('sysparm_num'), 'u_caller_name');
	},
	
	/*******************************************
	* Queries incidents for the given reference, either location or caller_id
	* Returns a count of active incidents not including current record
	********************************************/
	_query: function(ref, num, type) {
		var response = '';
		
		var count = new GlideAggregate('incident');
		count.addQuery(type, ref);
		count.addQuery('number', '!=', num);
		var qc = count.addQuery('state', '<', 6);	//not resolved/closed
		qc.addOrCondition('state', '>', 7);		//include pending vendor (or any status above closed 7)
		count.addQuery('sys_class_name', 'incident');	//not an incident task
		count.addAggregate('COUNT');
		count.query();
		
		var incidents = 0;
		if (count.next()) {
			incidents = count.getAggregate('COUNT');
			
			if (incidents > 0) {
				var pluralText = 'Incident.';
				if (incidents > 1)
					pluralText = 'Incidents.';
				
				if (type == 'location')
					response = 'Location has ' + incidents + ' active ' + pluralText;
				else if (type == 'caller_id')
					response = 'Caller has ' + incidents + ' active ' + pluralText;
			}
		}
		
		return response;
	},
	
	/*******************************************
	* Queries shared services for the given reference, either location or caller_id
	* Returns a count of active records not including current record
	********************************************/
	_querySharedServices: function(ref, num, type) {
		var response = '';
		
		var count = new GlideAggregate('u_shared_services');
		count.addQuery(type, ref);
		count.addQuery('number', '!=', num);
		count.addQuery('state', '<', 6);	//not resolved/closed
		//qc.addOrCondition('state', '>', 7);		//include pending vendor (or any status above closed 7)
		//count.addQuery('sys_class_name', 'u_shared_services');	//not a subtable
		count.addAggregate('COUNT');
		count.query();
		
		//gs.info('LCGIncCheck: ' + ref + ' ' + num + ' ' + type, 'LCGIncCheck');
		
		var incidents = 0;
		if (count.next()) {
			incidents = count.getAggregate('COUNT');
			//gs.info('LCGIncCheck: Query found results ' + incidents);
			if (incidents > 0) {
				var pluralText = 'case.';
				if (incidents > 1)
					pluralText = 'cases.';
				
				if (type == 'location')
					response = 'Location has ' + incidents + ' active ' + pluralText;
				else if (type == 'u_employee_name')
					response = 'Employee has ' + incidents + ' active ' + pluralText;
				else if (type == 'u_caller_name')
					response = 'Caller has ' + incidents + ' active ' + pluralText;
			}
		}
		
		return response;
	}
});

 

Justin Scheich
Tera Guru

I was able to find the solution; The script included does work without a change. It would appear that 

if (g_form.getDisplayBox('caller_id').value == '')

is not supported in the workspace and instead needs to be. 

if (g_form.getValue('caller_id') == '')