Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

List link to attachment

jcanuel
Kilo Explorer

Hi,

In the sys_attachment list, clicking an item in the file name column opens the "Save to" dialog box. Is it possible to reproduce that fonctionality in a custom table where all record contain one attached file ?

Thanks

1 ACCEPTED SOLUTION

Hello Jacques,



I was doing more testing with this. At the end it wasn't as complicated as I though at first. You have two options (Option 2 is better from my point of view):



Option 1:


Modify the field that you created to be a Reference field to the sys_attachment table.


Change the advanced calculation to:


  1. var attachment = new GlideRecord('sys_attachment');  
  2. attachment.get('table_sys_id', current.sys_id);  
  3. current.nameOfTheCreatedFiled= attachment.sys_id;  


Option 2:


Modify the field that you created to be a Reference field to the sys_attachment table.


Implement a business rule that runs before insert and before update (on your table) to populate the field that you created with the corresponding value:(Actually it would be the same code)



  1. var attachment = new GlideRecord('sys_attachment');  
  2. attachment.get('table_sys_id', current.sys_id);  
  3. current.nameOfTheCreatedFiled= attachment.sys_id;  


Thank you.



Regards


View solution in original post

5 REPLIES 5

Raju Koyagura
Tera Guru

I guess this functionality may be browser dependent, In chrome we will not get the "Save to" dialog box, where as in IE we can. .


edwin_munoz
Mega Guru

Hi Jacques,



I think something like this should work. I'm not sure about how good performance will be though. Possibly there is another way to do it.



Create a custom URL field in your table. Select the Calculated checkbox. On the calculation field type this:



var attachment = new GlideRecord('sys_attachment');


attachment.get('table_sys_id', current.sys_id);




var link = '<a class="linked formlink" href="sys_attachment.do?sys_id=';


link+= attachment.sys_id;


link+= '">' + current.nameOfYourNameWithTheName + '</a>';




current.nameOfTheCreatedFiled= link;


Thank you Edwin,



It works fine in a form, but I need to make it work in a list (and it doesn't) !


Hello Jacques,



I was doing more testing with this. At the end it wasn't as complicated as I though at first. You have two options (Option 2 is better from my point of view):



Option 1:


Modify the field that you created to be a Reference field to the sys_attachment table.


Change the advanced calculation to:


  1. var attachment = new GlideRecord('sys_attachment');  
  2. attachment.get('table_sys_id', current.sys_id);  
  3. current.nameOfTheCreatedFiled= attachment.sys_id;  


Option 2:


Modify the field that you created to be a Reference field to the sys_attachment table.


Implement a business rule that runs before insert and before update (on your table) to populate the field that you created with the corresponding value:(Actually it would be the same code)



  1. var attachment = new GlideRecord('sys_attachment');  
  2. attachment.get('table_sys_id', current.sys_id);  
  3. current.nameOfTheCreatedFiled= attachment.sys_id;  


Thank you.



Regards