UI Action and Scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hello!
I've been learning implementation of servicenow and I'm trying to create a copy case button, when we click on the button it should create a new case copying the short description from that case and also update the work notes as 'copied from csxxxxx'.
I can create UI Action, but I have doubts about the scripting part. Could anyone please explain how we can write script for that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
You can achieve this by creating a UI Action that inserts a new Case record and copies the required values from the current record.
Here is a simple approach.
1. Create the UI Action
Table: Case
Action name:
copy_caseCheck Form button checkbox
Uncheck Client checkbox
2. Script Example
var newCase = new GlideRecord('sn_customerservice_case');
newCase.initialize();
// Copy short description from the current case
newCase.short_description = current.short_description;
// Add work note referencing the original case
newCase.work_notes = 'Copied from ' + current.number;
var newSysId = newCase.insert();
// Redirect to the new case
action.setRedirectURL(newCase);Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a minute ago
Script:
var currentCase = current;
var newCase = new GlideRecord('sn_customerservice_case');
newCase.initialize();
// short description
newCase.short_description = currentCase.short_description;
// Add work notes with the reference
newCase.work_notes = 'Copied from ' + currentCase.number;
var newCaseID = newCase.insert();
action.setRedirectURL(newCase);
A few things to keep in mind:
- Make sure your UI Action is set to run on the server side (not client-side)
- The table name for cases is typically 'sn_customerservice_case' but double-check yours since it can vary depending on your instance setup
