It also works in a custom scope and in a Script Include that is used for other things and has more functions. Nice solution!

Example:

var CustomTemplateUtil = Class.create();
CustomTemplateUtil.prototype = {

	getAvailableTemplates: function(tableName, recordSysId) {
		// ...
	},
	
	applyTemplate: function(recordSysId, templateSysId) {
		// ...
	},

	/**
	 * Returns the table names available for the table selection field on the form.
	 * ! Attention: Do not change this function name. It is used by the internal ServiceNow logic.
	 */
	process: function() {
		var tableNames = ['x_custom_request', 'x_custom_task', 'x_custom_project'];
		return tableNames;
	},

    type: 'CustomTemplateUtil'
};

 

PaulKunze_0-1747832692077.png