Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query attachment from a Message record

Through the UI, I have created several Message records attached to a Support Ticket record, two of which have file attachments. I have been able to retrieve the ticket, and its related messages in Suitescript - which are correctly reporting hasAttachment as 'T' - but I cannot seem to access the attachments themselves. The documentation states that the attachments are a sublist called 'mediaitem' (or 'mediaitemlist', depending on where you look), but none of the sublist APIs have any success on those names.

    var record = nlapiLoadRecord('message', 1092823, {recordmode: 'dynamic'});
    var itemCount = record.getLineItemCount('mediaitem');
    // returns -1

The documentation and other online info is pretty sparse, so any help would be greatly appreciated.

like image 800
Chris Barcroft Avatar asked Oct 23 '15 21:10

Chris Barcroft


People also ask

How do I query all notes and attachments in Salesforce?

You can query them simply: List<Note> notes = [SELECT Id FROM Note WHERE ParentId = :myRecord]; List<Attachment> attachments = [SELECT Id FROM Attachment WHERE ParentId = :myRecord];

What is a message attachment?

An attachment is simply an additional file sent with an email message. An attachment can be an image file, a Word document, or one of many other supported file types.


1 Answers

Yeah, indeed there is a poor documentation. And mediaitem sublist did not help me either to give any meaningful result.

However, there is an alternate solution to it.

Create a saved search from UI on message record type.

Make sure you add a search column Attachments : Internal ID (i.e. using attachment fields...)

Once, this is done, run your search in suitescript as

var res = nlapiSearchRecord('message', 'YOUR_UI_SEARCH_ID', ARRAY_OF_ADDITIONAL_FITLTERS);
res[i].getValue('internalid', 'attachments')
like image 126
prasun Avatar answered Oct 20 '22 16:10

prasun