Change attachment name by Business Rule

ma kaiyue
Giga Guru

When a new record is added to the sys_attachment table, I want to upload this attachment to the AWS cloud, but I want to change the name of this attachment (add the time stamp) before uploading. What should I do?

 

Thanks in advance!

2 REPLIES 2

swathisarang98
Giga Sage
Giga Sage

Hi @ma kaiyue ,

 

You can create a before insert business rule on sys_attachment table as attached below,

 

Here i am checking for particular item you can change the code according to your requirement,

swathisarang98_0-1709632631045.png

 

swathisarang98_1-1709632652909.png

 

 

(function executeRule(current, previous /*null when async*/) {

	var attachmentRitm = new GlideRecord('sc_req_item');
	attachmentRitm.addQuery('sys_id', current.table_sys_id);
	attachmentRitm.addQuery('item','Get user Detail');
	attachmentRitm.query();
	if(attachmentRitm.next()){
		gs.info('inside if ');
		var nameFile ="RITM Attachment for item Get user Detail";
		var extensionName = current.getValue("file_name").split(".")[1];

		current.file_name = nameFile + "." + extensionName;
	}

})(current, previous);

 

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,

Swathi Sarang

 

@ma kaiyue ,Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.

 

Thanks,

Swathi