Automatically rename the attachment present in form record

Nikhil55
Tera Contributor

I need way to rename an attachment when ever a new attachment is attached to form. can any one help me to acheive this?

1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage
Mega Sage

Hi @Nikhil55 ,

 

You can write a before insert BR on sys_attachment table with below script :

 

Please make sure you select the table name for which you want this to happen else it will be a global change

 

kamlesh8_0-1666692744370.png

 

You can use the below script:

 

 

 

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

	// Add your code here

       var name = "MyCustomName" // You can set the value as per your requirement
	var extensionName = current.getValue("file_name").split(".")[1]; //Retrieves the extension of file your are uploading
	current.file_name = name + "." + extensionName // Renaming the uploaded file along with it's extension

})(current, previous);

 

 

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

 

View solution in original post

3 REPLIES 3

Edgar10
Tera Guru

Hi Nikhil,

 

Create an After insert business rule on sys_attachment table.

Add conditions so that it only triggers for your case table.

 

Regards,

 

Nikhil55
Tera Contributor

Hi @Edgar10 , Thank you for your response!

Can you please provide sample script if you are having. It will be helpful.

kamlesh kjmar
Mega Sage
Mega Sage

Hi @Nikhil55 ,

 

You can write a before insert BR on sys_attachment table with below script :

 

Please make sure you select the table name for which you want this to happen else it will be a global change

 

kamlesh8_0-1666692744370.png

 

You can use the below script:

 

 

 

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

	// Add your code here

       var name = "MyCustomName" // You can set the value as per your requirement
	var extensionName = current.getValue("file_name").split(".")[1]; //Retrieves the extension of file your are uploading
	current.file_name = name + "." + extensionName // Renaming the uploaded file along with it's extension

})(current, previous);

 

 

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh