- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 07:08 AM
I have been asked to check the attachment header of a request.
I have tried using an attachment variable and got it to work. I have a client script that takes the sys-id of the attachment and calls an include script that checks the format and hedears with a GlideSysAttachment();
The problem is that I am asked to do this without the attachment variable and instead with the 'paperclip' attachments. And I don't know how to get the sys-id of these attachments.
With the simplemtente variable I can get it with this:
var attachmentSysID = g_form.getValue('attachment');
But I have no idea how to do it without the variable. Does anyone have any idea how to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 04:37 PM - edited 06-15-2025 04:21 PM
I'm not too clear on what exactly you're after - the attachment sys_ids or the record that the attachment will be added to, so here's how to get both in a client script. Noting that both of these solutions require inspecting the DOM, so there is a small dependency on this and thus not recommended, but I don't believe there is another way without it
Get an array of attachments
You can get an array of attachments in a catalog client script (running on the portal) by inspecting the angular scope like so:
var $scope = this.angular.element("#sc_cat_item").scope();
var attachmentSysIds = $scope.attachments.map(function(attachmentDetails) {
return attachmentDetails.sys_id;
});
// Result is an array of sys_attachment sys_ids:
// ["5cf0d22453b9121036a838f0a0490e55", ...]
Get the sys_id of the to be record
You can get the sys_id of the record that's about to be generated by also looking at the angular scope, but at different properties (this is for catalog client scripts running on the portal):
var $scope = this.angular.element("#sc_cat_item").scope();
var toBeTableName = $scope.data._attachmentTable;
var toBeSysId = $scope.data._generatedItemGUID;
// Result is the record the Record Producer is going to create, for Catalog Items, this is the `sc_cart_item` record:
// toBeTableName = incident
// toBeSysId = 2943522053f9121036a838f0a0490e78
// You can query the sys_attachment table's `table_name` and `table_sys_id` fields that match the above to find the attachments uploaded.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 07:23 AM
@PereR Use a GlideAjax call from the client script to a Script Include, which will use the GlideSysAttachment API to retrieve attachment information.
Your script might be something like below:
Script include (AJAX):
// Script Include to get attachment sys_id(s) for a record
var AttachmentHelper = Class.create();
AttachmentHelper.prototype = {
initialize: function() {},
getAttachmentSysIDs: function(recordSysId, tableName) {
var attachmentIds = [];
var ga = new GlideSysAttachment();
var attachments = ga.getAttachments(tableName, recordSysId);
while (attachments.next()) {
attachmentIds.push(attachments.sys_id.toString());
}
return JSON.stringify(attachmentIds); // Return as JSON array of sys_ids
},
type: 'AttachmentHelper'
};
And then you can call in your client script to get sysid of attachment even you can amend script include if needed to get name of attachment as well.
Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 12:08 AM
I have something similar the problem is that I don't know how to get the recordSysId, I have tried with g_form.getUniqueValue() but it doesn't match the table sys id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 12:39 AM
@PereR If you request is not yet submitted then that would be the reason , if so you will have to use BR on sys_attachment to validate same before update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2024 10:33 AM
I have to check the headers before submitting, so I do it in the client script onSubmit. How could I do it with a br?