Script include function not working when called from client side

Khalnayak
Tera Guru

Hi all,

I have a record producer on which I want to show the assignment group the HR case will be assigned to.

SO I have a script include within which I am calling a function and then using a onchange client side script to call the script include and display the group in the item.

This is the code for the getAG function in the script include.

getAG: function(){
		//var current = this.getParameter('sysparm_current');
		gs.debug('HR AG');
		var subjectPerson = this.getParameter('sysparm_req_for');
		var prodID = this.getParameter('sysparm_prodID');
		var contactType = 'Self Service';
		//var source = '[producer.source]';
		var AG = '';


		var grHrService = new GlideRecord('sn_hr_core_service');
		grHrService.get('producer', prodId);

		var currentServiceTable  = grHrService.getValue('service_table');
		var currentTopicCategory = grHrService.topic_detail.topic_category.getDisplayValue();
		var currentTopicDetail   = grHrService.topic_detail.getDisplayValue();
		var currentHRServiceName = grHrService.getDisplayValue('name');


				var grSubjectPerson = new GlideRecord('sys_user');
				grSubjectPerson.get(subjectPerson);

				var currentLocation = grSubjectPerson.getValue('location');

				var grCase = new GlideRecord(currentServiceTable);
				grCase.setValue('hr_service',     HrService);
				grCase.setValue('contact_type',   contactType);
				grCase.setValue('source',         source);
				grCase.setValue('subject_person', subjectPerson);
				grCase.setValue('location',       currentLocation);


				var grAssignmentRule = new GlideRecord('sysrule_assignment');
				grAssignmentRule.addActiveQuery();
				grAssignmentRule.addQuery('table', '=', currentServiceTable);
				grAssignmentRule.orderBy('order');
				grAssignmentRule.query();

				var filter;
				var found = false;

				while ( grAssignmentRule.next() && found == false ) {

					filter = grAssignmentRule.getValue('condition');

					if ( filter == '' ) {
						continue;
					}

					found = GlideFilter.checkRecord(grCase, filter, true);

					if ( found ) {
						gs.info('HR AG match: ' + grAssignmentRule.getDisplayValue('group'));
						gs.log('HR AG match: ' + group);
						AG = grAssignmentRule.group;
						return AG;
					}

				}

				if ( found == false) {
					gs.info('HR AG: no match');
				}},

 

and then this is the client script that is calling the script include function:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	
	var ga = new GlideAjax('sn_hr_core.HRCaseAccessRP');
	ga.addParam('sysparm_name', 'getAG');
	ga.addParam('sysparm_req_for', producer.requested_for);
	ga.addParam('sysparm_prodID', g_form.getUniqueValue());
	
	ga.getXMLAnswer(getResponse);

	function getResponse(response){
		var answer = JSON.parse(response);
		g_form.addInfoMessage(answer.AG);
		g_form.setValue('assignment_group', answer.AG);
	}


   //Type appropriate comment here, and begin script below
   
}

 

so the onchange client script works in the sense it displays the showfield message banner so the blue bit under the field. But there is no data or group shown in the field message. it is blank.

find_real_file.png

I have added some gs.logs within the script include function I am calling but they are not displaying in the logs at all.

So looks like script include is not being called.

The script include is in the HR core app scope and the client script is in the employee center core scope.

The script include caller access is set to none so that should not restrict and accessible from is all app scopes.

Can someone help me on this please.

 

1 ACCEPTED SOLUTION

Kailash Bhange
Kilo Sage
Kilo Sage

Hi Khalnayak,

I suppose your code is failing at below highlighted lines as the variable defined is different one here, please make corrections.

 

find_real_file.png

 

Hope this helps.
If my answer resolves your issue, please mark my answer as ✅ Correct & Helpful based on the validations.

Thank You!
Regards,
Kailash

View solution in original post

17 REPLIES 17

Hi

see the following video for the try-catch-block: https://www.youtube.com/watch?v=-PAI9jmUWMM

For debugging best practices see https://developer.servicenow.com/dev.do#!/guides/rome/now-platform/tpb-guide/debugging_best_practice...

Kind regards
Maik

Thanks @Maik Skoddow but I think the script include is not even running hence why not seeing any errors or so.

None of the gs.log or gs.info are being logged at all.

I only see one log that is related to my script include and that is this:

find_real_file.png

ccan you advise if this could be the cause and how I could fix it

Harshal Gawali
Giga Guru

Hi,

Make sure that client callable checkbox should be checked in your script include.

Regards,

Harshal.

@Harshal Gawali it is checked

find_real_file.png

Adrian Ubeda
Mega Sage
Mega Sage

Hi Khalnayak,

In you script include is 'client callable' flag checked? Also should access from all application scopes.
Apart from that, review is there is any restricted caller access record between apps for this SI in sys_restricted_caller_acces table, if status is invalidad change that record to allowed.

If it was helpful, please give positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆