The CreatorCon Call for Content is officially open! Get started here.

Attachment in sc catalog item widget

hadarzec
Kilo Contributor

Hi:)

In the widget client script I see that attachment is saved in 'sp_portal', where does it change the location and add the attachment to the correct item?

this is the line:

var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});

ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);

5 REPLIES 5

kristian dimitr
Tera Guru

Hello Hadar,



The record is inserted into the sys_attachment table and then is updated to the correct item, for example the table name field will be changed from sp_portal to sc_request.



Kristian Dimitrov!


hadarzec
Kilo Contributor

Hello Krisian,



can you show me where is the code that change the table name field?


Hi Hadar,



I have been investigating the same today and I found so far that we do not have the access to the code as it is encapsulated in a java code probably. The logic is as following (at least on Helsinki:


- SC Catalog Item widget generated _attachmentGUID which is used to store the attachments - those are linked to "sp_portal" table and the attachmentGUID


- Once you click Submit button - the function "postCatalogFormRequest" is called (defined in Client Controller)


- This function calls $http.post which results in a call to angular.do URL with some parameters like sysparm_type=$sp and typ=sc_cat_item and also passing the payload including attachmentGUID


- There is Processor called AngularProcessor which has path "angular" so this is probably called, but since it is Java processor I cannot see what happens then - where I could find a code which is then relinking attachments based on the attachmentGUID to the target record. If somebody has idea what happens there, I would be interested.



Since my use case was for a Record Producer where we decide dynamically if Incident or Change should be created and we are aborting insert of current record, I was trying to find out if the attachments are relinked to the current record before or after "Script" of record producer is executed. And the result is that it is before, which is bad because you do not know "attachmentGUID" in the record producer so you cannot relink the attachments easily to the records created by us in the script.



I have solved it by adding variable "attachments_ids", onSubmit catalog client script which copies sys_ids of attachments to the variable, script in the record producer which relinks those attachments to the record of my wish. Maybe it helps somebody.


Hi Dominik,



I'm interested in how you implemented this part:


I have solved it by adding variable "attachments_ids", onSubmit catalog client script which copies sys_ids of attachments to the variable, script in the record producer which relinks those attachments to the record of my wish.



Any chance you could share your code?


Where did you put this client script? what table does it run on?


Does this get the actual sys_id of the attachment for the sc_req_item table, as it appears in the sys_attachment table after it has been updated from the temporary sys_id for the sp_portal table?



Thanks


Tim