How can i get the atttachments sys_id before Submit a form?

PereR
Tera Contributor

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?

1 ACCEPTED SOLUTION

Nick Parsons
Mega Sage

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.

 

View solution in original post

12 REPLIES 12

thanks, getting the sys_id of the registry to be, that's exactly what I needed and I had no idea how to get it

I haven't seen another way to do it either. Been trying for so long, but only way to retrieve the table_sys_id for the attachment is with DOM manipulation. g_form.getUniqueValue gives you the sys_id of the cat item, there are really no other ways to access the attachment information. 

Actually, if your use case only allows one attachment upload you should use a attachment variable. Then you can pull that attachments sys_id with g_form  and do a GlideAjax. But if you're using the OOB attachment at the bottom of a cat item you need to do DOM manipulation as shown above!