Tech tactics
Simple tactics that change the life of
your code
Hazim khasawneh
Sharing ideas and tips that help a front-end
developer in his daily life.
Weekly Posting Schedule
Join me every Sunday at 11 AM (Jordan time)
for a new document filled with valuable insights!
Introduction: This document is part two of a two-part series on scripting in
ServiceNow.
Focus: Detailed exploration of server-side scripting.
Previous Part: Client-side scripting was covered in the first document.
What is Server-Side Scripting?
Server-Side Scripting involves scripts that execute on the server, handling
critical data processing and business logic operations.
These scripts are essential for managing complex workflows, ensuring
data integrity, and automating business processes efficiently.
Types of Server-Side Scripts:
Business Rules: Automate actions or enforce data integrity rules when
records are inserted, updated, or deleted.
Script Includes: Encapsulate reusable logic and functions accessible across
the platform.
Scheduled Jobs: Execute scripts at specified intervals to perform
automated tasks, such as data cleanup or reporting.
Business Rules
Business Rules are scripts that automate actions during record operations
such as insert, update, or delete.
Types of Business Rules:
Before: Executes before the database operation.
After: Executes after the database operation.
Async: Executes asynchronously.
Display: Executes when a record is displayed.
Real-Life Example
This Business Rule automates the calculation of total costs for purchase
orders
Script Includes
Script Includes are containers for reusable server-side code in ServiceNow.
They encapsulate complex logic and functions, promoting code reuse across
the platform.
Example:
Implement a function to calculate business days between two given dates
with accuracy and efficiency.
Real-Life Example
This Script Include provides a
method to calculate business
days.
This method is accessible and
usable across various ServiceNow
server-side contexts, such as
business rules and custom
widget server-side scripts.
Scheduled Jobs
Scheduled Jobs are automated tasks in ServiceNow that run on predefined
schedules.
They perform periodic operations such as data cleanup, report generation, or
system maintenance.
Example:
Execute a daily data cleanup job to ensure data integrity and optimize system
performance.
Real-Life Example
✓ Navigate to Scheduled
Jobs.
✓ Create a new
Scheduled Job.
✓ Define the script and
schedule.
Best Practices for Server-Side Scripting
Keep It Simple: Write clear and concise code.
Avoid Duplication: Reuse code where possible.
Debugging: Use logs to debug scripts.
Performance: Optimize code for efficient server processing.
Security: Ensure scripts are secure and follow best practices.
Documentation: Comment your code for better understanding and
maintenance.
At The End.
Let's build a community where we share knowledge and simplify
tech. Simple insights can save time and effort for others in our
community.
Follow, comment , and repost useful content!
Thank you.