How to store attachment in sys_attachment table

Pallavi Shetty
Tera Contributor

I have below requirement in "WIDGET" where user is choosing files.

And i want to store it in sys_attachment table after clicking below "auto fill" button.

How can i achieve this.

find_real_file.png

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

which form/page is that?

Regards
Ankur

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

Markus Kraus
Kilo Sage

Hi, here is an example widget:
HTML

<div>
	<input name="myFile" type="file" />
  	<button ng-click="c.upload();" />
</div>

Client controller:

api.controller=function(snAttachmentHandler, spUtil) {
	var c = this;
	
	var table = 'problem';
	var sysId = '1998e51967b032004792adab9485effa';
	
	var handler = snAttachmentHandler.create(table, sysId, {
		onUploadComplete: function () {
			spUtil.addInfoMessage('upload success');
		}
	});
	
	c.upload = function () {
		var input = document.querySelector('#x' + c.widget.rectangle_id + ' input[name="myFile"]');
		if (input && input.files.length) {
			handler.uploadAttachment(input.files[0]);
		}
	};
};

Please let us know if this solved your problem.