Category:
Updated on: August 31, 2025  |  0

Server Side Scenarios 1 - Business Rules & Script Includes

🔧 Server-Side Scripting: Examples & Scenarios


📝 1. Business Rules

Business Rules run when a record is inserted, updated, deleted, or queried.

1.1 Auto-assign Incident to “Network Team” if Category = Network

 
if (current.category == 'network' && !current.assignment_group) { current.assignment_group.setDisplayValue('Network Support'); }

1.2 Prevent deletion of High-Priority Incidents

 
if (current.priority == 1) { gs.addErrorMessage("Critical incidents cannot be deleted!"); current.setAbortAction(true); }

1.3 Update “Resolved By” when Incident is closed

 
if (current.state == 7 && current.resolved_by.nil()) { // Closed current.resolved_by = gs.getUserID(); }

📦 2. Script Includes

Reusable server-side classes/functions that can be called from other scripts.

2.1 Script Include: Get User’s Active Incidents

 
var IncidentUtils = Class.create(); IncidentUtils.prototype = { initialize: function() {}, getUserIncidents: function(userId) { var gr = new GlideRecord('incident'); gr.addQuery('caller_id', userId); gr.addQuery('active', true); gr.query(); var results = []; while (gr.next()) { results.push(gr.number.toString()); } return results; }, type: 'IncidentUtils' };

2.2 Using GlideAjax (from Client Script)

 
var ga = new GlideAjax('IncidentUtils'); ga.addParam('sysparm_name', 'getUserIncidents'); ga.addParam('userId', g_form.getValue('caller_id')); ga.getXMLAnswer(function(response) { alert("User has active incidents: " + response); });

Comments

No comments yet.


Log in to post a comment