Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

UI Action and Scripting

Sujana Vadagana
Tera Contributor

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.

3 ACCEPTED SOLUTIONS

maliksneha9
Kilo Sage

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_case

  • Check 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!

View solution in original post

Sahil Chaudhary
Tera Expert

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

View solution in original post

Tanushree Maiti
Giga Sage

Hi @Sujana Vadagana 

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)
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

3 REPLIES 3

maliksneha9
Kilo Sage

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_case

  • Check 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!

Sahil Chaudhary
Tera Expert

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

Tanushree Maiti
Giga Sage

Hi @Sujana Vadagana 

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)
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: