- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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
yesterday
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Create a Ui Action 'Copy Case' , make it server-side code (Client - false)
Script:
var newCase = new GlideRecord('sn_customerservice_case');
newCase.initialize();
// Copy specific fieldsnewCase.short_description = current.short_description;
newCase.description = current.description;
newCase.company = current.company;
newCase.contact = current.contact;
newCase.account = current.account;
newCase.category = current.category;
newCase.subcategory = current.subcategory;
// Optional: Link back to original case
newCase.work_notes = 'Copied from ' + current.number;
var newSysId = newCase.insert();
// Redirect to new caseaction.setRedirectURL(newCase);
gs.addInfoMessage('Case ' + newCase.number + ' created from ' + current.number)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
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
yesterday
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
Create a Ui Action 'Copy Case' , make it server-side code (Client - false)
Script:
var newCase = new GlideRecord('sn_customerservice_case');
newCase.initialize();
// Copy specific fieldsnewCase.short_description = current.short_description;
newCase.description = current.description;
newCase.company = current.company;
newCase.contact = current.contact;
newCase.account = current.account;
newCase.category = current.category;
newCase.subcategory = current.subcategory;
// Optional: Link back to original case
newCase.work_notes = 'Copied from ' + current.number;
var newSysId = newCase.insert();
// Redirect to new caseaction.setRedirectURL(newCase);
gs.addInfoMessage('Case ' + newCase.number + ' created from ' + current.number)
