Copy attachments and add a work note when using a Copy Case UI Action - CSM project

Daniel R2
Kilo Sage

On our current project, we have created a UI action to copy a customer service case.

When a user selects the 'Copy Case' UI action in the CSM/FSM Workspace on a case form, we have configured it so a new form pops up with all the information copied on to it, the case is not created yet, as we have ensured that it is possible for the agent to edit any fields before they submit the request. 

The script we are using on the UI action is below. There are 2 questions we have here.

1. How can we ensure attachments are also copied over from the original to the new one? because we believe copying the attachment requires the sys id of the new case however the new case is not submitted yet. We should be able to see the attachments in the attachments tab when copying the case.

2. How can we add an automatic comment to the work notes? we would like the following comment to be populated in the work notes field: "Case Copied from + number of original case". We have tried a number of things such as:

newRecord.work_notes = "Case Copied from " + current.number; 

However this still doesnt add a comment to the work notes. We have tried other ways however it then the copy case button stops working all together.

 

var url;
var recID = current.sys_id;
var tasktype = current.sys_class_name;
var newRecord = new GlideRecord(tasktype);
newRecord.initialize();
newRecord.setValue("from_email", current.getValue("from_email"));
newRecord.setValue("short_description", current.getValue("short_description"));
newRecord.setValue("company", current.getValue("company"));
newRecord.setValue("category", current.getValue("category"));
newRecord.setValue("subcategory", current.getValue("sysubcategory"));
newRecord.setValue("email_body", current.getValue("email_body"));
newRecord.setValue("contact_type", current.getValue("contact_type"));
action.openGlideRecord(newRecord);

 

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

To get the record's sys_id before it's saved to the database you can use:

var sysID = newRecord.setNewGuid();

For work notes, those get logged to a journal entry field and so that's probably why you're having an issue trying to post something to it because the record hasn't been created yet with this step. You'd have to handle that as part of the record being inserted/created and so you may need to handle that in a before business rule, for example.

 

The only other methods are things like:

newRecord.setValue('work_notes', "Value here");
newRecord.setJournalEntry('work_notes', "Value here");
newRecord.work_notes = "Value here";

If none of those work, which they probably won't, then you'd have to handle in business rule or perhaps set the description field on this record, then use a business rule to copy that it's work notes, then clear the description.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thanks for the reply @Allen Andreas it is much appreciated. Our team will look into the copying the attatchment and sysid question. 

In terms of the business rule to add the necessary comment to the work note of the copied case. Have you got an example script you could provide here by any chance?

Hello,

If my reply above was Helpful, please mark it as such.

For the copying of an attachment, you'd want utilize the GlideSysAttachment API and the copy method, as shown here: https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/GlideSysAttachmentGlobal... 

 

For the business rule, you can create a before business rule on the respective table with the condition as "Description" contains "x" (if using the temp method I described above of placing that work note statement in the description initially) and then in the advanced tab for scripting, you'd simply use something like:

current.work_notes = current.description;
current.setValue('description', '');

Please try and work with that, adjust as needed.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!