ServiceNow Scripting
ServiceNow is a cloud-based platform that provides a suite of applications for IT service management (ITSM), IT operations management (ITOM), and business management. Scripting in ServiceNow is primarily done using JavaScript. Here are some key scripting components in ServiceNow:
javascript
(function executeRule(current, previous /*null when async*/) {
// Add your script logic here
gs.info("Business Rule ran for record: " + current.number);
})(current, previous);
2. Client Scripts:
Client Scripts run on the user's browser and are used to control form behavior, data validation, and other client-side operations.
Example Client Script script:
javascript
// Client Script for onChange event on a field
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Add your script logic here
alert('Field value changed to: ' + newValue);
}
3. Script Includes:
Script Includes are reusable JavaScript functions that can be called from other scripts. They help modularize code and encourage best practices.
Example Script Include script:
javascript
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {},
myFunction: function() {
// Add your script logic here
return 'Hello, World!';
},
type: 'MyScriptInclude'
};
领英推荐
4. Client Controllers:
Client Controllers are used to control client-side behavior in ServiceNow Service Portal.
Example Client Controller script:
javascript
angular.module('myModule').controller('MyController', ['$scope', function($scope) {
// Add your script logic here
$scope.message = 'Hello, World!';
}]);
5. UI Policies:
UI Policies are used to dynamically change the visibility, read-only, and mandatory attributes of form fields.
Example UI Policy script:
javascript
// Condition: [Priority] [is] [High]
current.priority == 1
6. Scheduled Jobs:
Example Scheduled Job script:
javascript
// Add your script logic here
gs.info("Scheduled Job ran at: " + new Date());
These are just a few examples of scripting in ServiceNow. Depending on your specific requirements, you might also encounter Business Rules, Events, Notifications, and other scripting components within the platform. The ServiceNow documentation is an excellent resource for detailed information and examples.