custom column in sys_attachment table

Mitisha Kukreja
Tera Contributor

Want  Attachment Type field on manage attachment screen.  i  want to save this selected attachment type  in sys_attachment table  against uploaded document .  how it is  possible ?

for refrence adding the image below

 

find_real_file.png

1 ACCEPTED SOLUTION

Markus Kraus
Kilo Sage

Note: The Solution presented here is for Quebec, i've noticed that at least the line numbers are different on San Diego (where i have *not* tested this solution yet).

The Screenshot you have posted shows a modification to the OOTB attachment UI Page: /nav_to.do?uri=sys_ui_page.do?sys_id=b1b390890a0a0b1e00f6ae8a31ee2697

What you have to do is the following (all Global Scope):

  1. Add a new Choice Field to the sys_attachment table
    find_real_file.png
  2. Create a Client Side Script Include that will write the attachment type after upload (i couldn't think of a better solution right now)
    var AttachmentTypeHelper = Class.create();
    AttachmentTypeHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    	// just the snippet
    	setAttachmentType: function () {
    		var attachmentType = this.getParameter('attachment_type');
    		var attachmentGr = new GlideRecord('sys_attachment');
    		if (attachmentType && attachmentGr.get(this.getParameter('attachment'))) {
    			attachmentGr.u_attachment_type = attachmentType;
    			attachmentGr.update();
    			return true;
    		}
    		
    		return false;
    	},
    
    	type: 'AttachmentTypeHelper'
    });
  3. Modify the attachment UI Page HTML:
    find_real_file.png
    Script to Copy & Paste:
    								<tr>
    									<td colspan="3">
    										${new GlideRecord('sys_attachment').getElement('u_attachment_type').getLabel()}:$[SP]<g:ui_choicelist name="attachment_type" table="sys_attachment" field="u_attachment_type" />
    									</td>
    								</tr>​
  4. Modify the attachment UI Page Client Script:
    find_real_file.png
    Code Snippet for Copy & Paste:
      var ga = new GlideAjax('AttachmentTypeHelper');
      ga.addParam('sysparm_name', 'setAttachmentType');
      ga.addParam('attachment', id);
      ga.addParam('attachment_type', $('attachment_type').value);
      ga.getXMLAnswer(function(){});


View solution in original post

3 REPLIES 3

Mitisha Kukreja
Tera Contributor

@Ankur Bawiskar  Please help me on this

Hi,

It's not recommended to customize OOB UI page

But if you still require then steps are mentioned below

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Markus Kraus
Kilo Sage

Note: The Solution presented here is for Quebec, i've noticed that at least the line numbers are different on San Diego (where i have *not* tested this solution yet).

The Screenshot you have posted shows a modification to the OOTB attachment UI Page: /nav_to.do?uri=sys_ui_page.do?sys_id=b1b390890a0a0b1e00f6ae8a31ee2697

What you have to do is the following (all Global Scope):

  1. Add a new Choice Field to the sys_attachment table
    find_real_file.png
  2. Create a Client Side Script Include that will write the attachment type after upload (i couldn't think of a better solution right now)
    var AttachmentTypeHelper = Class.create();
    AttachmentTypeHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    	// just the snippet
    	setAttachmentType: function () {
    		var attachmentType = this.getParameter('attachment_type');
    		var attachmentGr = new GlideRecord('sys_attachment');
    		if (attachmentType && attachmentGr.get(this.getParameter('attachment'))) {
    			attachmentGr.u_attachment_type = attachmentType;
    			attachmentGr.update();
    			return true;
    		}
    		
    		return false;
    	},
    
    	type: 'AttachmentTypeHelper'
    });
  3. Modify the attachment UI Page HTML:
    find_real_file.png
    Script to Copy & Paste:
    								<tr>
    									<td colspan="3">
    										${new GlideRecord('sys_attachment').getElement('u_attachment_type').getLabel()}:$[SP]<g:ui_choicelist name="attachment_type" table="sys_attachment" field="u_attachment_type" />
    									</td>
    								</tr>​
  4. Modify the attachment UI Page Client Script:
    find_real_file.png
    Code Snippet for Copy & Paste:
      var ga = new GlideAjax('AttachmentTypeHelper');
      ga.addParam('sysparm_name', 'setAttachmentType');
      ga.addParam('attachment', id);
      ga.addParam('attachment_type', $('attachment_type').value);
      ga.getXMLAnswer(function(){});