Query on attachments in service portal

Ahmmed Ali
Mega Sage

Hello All,

 

I have a requirement to copy attachment from existing record and populate it on new Catalog item in service portal.

For example, lets say there is one incident and below that incident number, there is a link to catalog item. When user opens that link, all the attachments in the incident should be populated on the catalog item form.

Then user can remove/attach new attachments and submit form.

 

Thanks and Regards,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali
1 ACCEPTED SOLUTION

Hello Jaspal,

 

Thank you for your response.

 

I was able to fulfill my requirement by reading unique GUID generated on catalog item widget and by copying records to that sys_id.

I am using record producer, hence the attachments are added with actual table name in attachments table and actual sys_id  (which will be generated as soon as the form is loaded in portal, same I am reading in my script and using to copy attachments).

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

10 REPLIES 10

Jaspal Singh
Mega Patron
Mega Patron

Hi Ahmmed,

 

Few days ago there was an article published for the same that does copy the same to Email Client Template. Something similar can be done for your case. You can refer link & give it a check.

Hi Jaspal,

 

Thank you for response.

 

Yes, If any record was getting created then I would have used GlideSysAttachment() API at server side. But here since catalog item is not yet submitted and there is no record in server side for the item, I am not able to figure it out how to do it.

 

Please suggest.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi @Ahmmed Ali,

If you'd invoke the newRecord() function on the GlideRecord, and set your sys_id variable with that newRecord value (instead of initialize()), you'll get a sys_id for the glide record that your action would eventually create. You should be able to use that sys_id to associate the attachments.

If you look at any of the records on the platform view, when you click on New, it just opens a blank form, the record hasn't been created yet, and still at that point, users are able to use the pin at the top to associate attachments to the record. I've used the <sp-attatchment-button> on one of my portal's widget using newRecord() to get the sys_id, before the record was committed to the ServiceNow table.

var gr= new GlideRecord('your_table');

data.sys_id = gr.newRecord();

Thanks & Regards,

Rishabh Jha

Aavenir (https://www.aavenir.com/)

Hi Ali,

 

Not sure if you are aware but until catalog item is submitted any attachment that is attached before submission is stored in sys_attachment table with table as sc_cart_item.

You can use the same table to copy attachment TO from your required incident.

So, source is incident while the target becomes sc_cart_item.