Requirement related to Work Notes and Attachments

Community Alums
Not applicable

Hi All,

 

I have few requirements related to Work notes and Attachments:

 

1. I want to get value of latest work notes, getJournalEntry(1) gives me something like this :

21/10/2024 11:55:23 - Hrithik Nirupam (Additional comments)\n Attachment Alert Sample Payload.txt added\n\

 I want only Attachment Alert Sample Payload.txt added, i.e. the value of the work notes not the whole entry.

 

2. I am sending attachments as base-64 encoded in JSON. Requirement is that if I select multiple files as attachments all at once, what logic should I use in Attachment Table so that I am able to pick the individual files, at the moment I have this logic below to query the attachments:

 

        var attach = {};
        var taskAttach = new GlideRecord('sys_attachment');
        taskAttach.addQuery('table_sys_id', incTask.sys_id);
        taskAttach.orderByDesc('sys_created_on');
        taskAttach.setLimit(1);
        taskAttach.query();
 
Problem with the above code is that even if I multiple select 2 files Alert.txt and Incident.txt, it is getting created in attachment table at the same time and hence, instead of picking 2 different files both the times Alert.txt is getting picked. Requirement is to send different files twice.
 
Can someone please help me with these requirements?
 
Thanks and Regards,
Hrithik Nirupam. 

 

1 REPLY 1

sejal1107
Tera Guru

 

Hi @Community Alums 

please try it once

 

var attach = {};
var taskAttach = new GlideRecord('sys_attachment');
taskAttach.addQuery('table_sys_id', incTask.sys_id);
taskAttach.orderBy('sys_created_on'); // Order by created on date
taskAttach.query();
while (taskAttach.next()) {
 
    var fileName = taskAttach.file_name; // Get the file name
    var sysId = taskAttach.sys_id; // Get the sys_id for each attachment
    attach[fileName] = sysId; // Store in an object for later use
}

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers

Thanks,

Sejal

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan