How to create a copy case UI action

Daniel R2
Kilo Sage

Hi,

 

We are currently trying to create a UI action to appear in CSM/FSM Workspace, that copies a case and creates a new case with the same information.

 

We have added the following script to the 'Workspace Client Script' field on the UI Action

 

 

var gr = current.sys_id.toString();
var newCase = new GlideRecord('sn_customerservice_case');
newCase.initialize();

newCase.from_email = current.from_email;
newCase.short_description = current.short_description;
newCase.company = current.company;
newCase.category = current.category;
newCase.subcategory = current.subcategory;
newCase.email_body = current.email_body;
newCase.work_notes = "Copied from Case " + current.number;
newCase.insert();

 

 

However, our cases are attached to a variety of tables extended from the 'sn_customerservice_cases' table. The new copied cases should be created on the exact same table as the original case. How can I ensure It is created on the same table, from one UI action

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Daniel R2 

you cannot use current object in workspace client script.

why not use GlideAjax there and pass the current record sysId using g_form.getUniqueValue() and then in script include function have the logic define.

you can also pass the current table name to script include via GlideAjax using g_form.getTableName()

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Daniel R2 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar - thanks for the reply Ankur, we have now changed the way we have configured this so that a new case opens with all the copied information but it is not created so a user has the possibility to edit if necessary before submitted. 
When selecting the copy case UI action, what script can we add to the UI action to ensure a comment is added to the work notes. We would like to add "Case copied from + the number of the original case"

@Ankur Bawiskar we are also struggling on copying attachments. This is because the case is not submitted yet so it can not get the sys id of the original case.