How to override the functions called by HR record producer scripts?

pascalfrencken
Mega Sage

In our HR service catalog on our HR portal we have many service catalog items that leverage record producers to turn employees' requests into HR cases. Out-of-the-box (OOB), the HR record producer scripts call functions in the sn_hr_core.hr_ServicesUtil script include to pass the information entered by the employee into the case.

We now have a requirement that demands changes to these functions. We don't want to customize the OOB functions, and are instead looking at creating a wrapper around this script include to override the functions. So far however, we've been unable to get this to work.

What we've done is create a custom script include within the same sn_hr_core scope that overrides the functions as follows:

var SIG_hr_ServicesUtil = Class.create();
SIG_hr_ServicesUtil.prototype = Object.extendsObject(sn_hr_core.hr_ServicesUtil, {
	initialize : function(_case, _gs) {
		sn_hr_core.hr_ServicesUtil.initialize.call(_case, _gs);
	},

	createCaseFromProducer : function(producer, rpId) {
		... (our custom code here)
	},

	type: 'SIG_hr_ServicesUtil'
});

 In our record producer script we call the custom function as follows:

 new sn_hr_core.SIG_hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

However, when doing so and submitting a service catalog item from our portal, we get an error and the overriding is not working:

org.mozilla.javascript.EcmaError: undefined is not a function.
Caused by error in <refname> at line 1

==> 1: new sn_hr_core.SIG_hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

What are we overlooking here? Is it even possible to override the OOB functions without customizing the script include?

Best regards,

Pascal Frencken
IT Architect, Signify, The Netherlands

1 ACCEPTED SOLUTION

Hi,

You should create that script include in HR Core Scope and Accessible from All scopes.

the OOB Script Include is in HR Core Scope -> hr_ServicesUtil

Are you trying to include this in record producer present in global scope

If you are trying to add restricted caller access then source scope should be global scope

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

seems error because of the gs variable/object you are using

what functionality you are to trying to achieve?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

The gs object is the GlideSystem, which is available. Why would that cause an issue?

The functionality we're trying to achieve is to override the OOB createCaseFromProducer() function to only put variables in the case that were actually shown on screen in the service catalog item. Right now with the OOB functionality also values of hidden variables are passed into the case, which is not what we want.

Best regards,

Pascal Frencken
IT Architect, Signify, The Netherlands

Hi Pascal,

You may find below link helpful https://community.servicenow.com/community?id=community_question&sys_id=364047a1db98dbc01dcaf3231f96...

If you this setup in PDI instance, please share ONLY link with me and I can take a look.

Thanks @Pradeep Sharma for your support. The issue actually occurred in one of our companies' instances, but I've been able to reproduce it in my PDI at https://dev86887.service-now.com/. Here's the configuration I did there:

  1. Created script include SIG_hr_ServicesUtil that extends hr_ServicesUtil
  2. Modified the record producer for the Direct Deposit Inquiry to call SIG_hr_ServicesUtil

When creating a Direct Deposit Inquiry via Employee Service Center the same error 'The undefined value has no properties' appears in the logs.

I have been unable to find what causes this to fail. If you could have a look, that would be highly appreciated.

Best regards,

Pascal Frencken
IT Architect, Signify, The Netherlands