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
Giga 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.

2 REPLIES 2

maliksneha9
Tera Expert

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 Contributor

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