Undefined when calling script include from background script

Brent Caudill
Tera Contributor

I am attempting to test a script include that will be used in a Transform rule in the Integrationhub ETL. The script looks up a computer CI using the passed in serial number.

I have tried a few variations of both the background script and script include, but it seems as if the script include isn't being called correctly. It returns 'script: undefined' from the gs.print. The gs.log actions in the script include are not showing up in the system logs.

Not sure what I'm doing wrong, so any help would be appreciated.

 

Background script:

var serialNumber = '123456';
var ci_discoverySource = new global.CIUtils().getComputerBySerialNumber(serialNumber);
gs.print(ci_discoverySource);

 

Script Include:

Name: CIUtils 
Application: Global
Accessible from: All application scopes

var CIUtils = Class.create();
CIUtils.prototype = {
    initialize: function() {
    },
	getComputerBySerialNumber: function(serialNumber) {
	gs.log(serialNumber);
	var computerGR = new GlideRecord('cmdb_ci_computer');
    computerGR.addQuery('serial_number', serialNumber);
    computerGR.query();

    if (computerGR.next()) {
		gs.log(computerGR.discovery_source);
		return computerGR.discovery_source; // Return the discovery source if found
        } else {
            return null; // Return null if not found
        }
    },
    type: 'CIUtils'
};


If I run the function directly in the background script it correctly returns the discovery source.

Working Background script:

var serialNumber = '123456';
getComputerBySerialNumber(serialNumber);
function getComputerBySerialNumber(serialNumber) {
	gs.log(serialNumber);
	var computerGR = new GlideRecord('cmdb_ci_computer');
    computerGR.addQuery('serial_number', serialNumber);
    computerGR.query();

    if (computerGR.next()) {
		gs.log(computerGR.discovery_source);
		return computerGR.discovery_source; // Return the discovery source if found
        } else {
            return null; // Return null if not found
        }
    }
1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @Brent Caudill 
The issue lies with your script include name. There is already an OOB script include with the same name, CIUtils. Please change your script include name, and it should work.

Regards,

Siva

View solution in original post

3 REPLIES 3

J Siva
Tera Sage

Hi @Brent Caudill 
The issue lies with your script include name. There is already an OOB script include with the same name, CIUtils. Please change your script include name, and it should work.

Regards,

Siva

Doh! Thank you @J Siva ! Can't believe I didn't catch that, but thank you very much!

@Brent Caudill Glad it helped 👍