Add date as prefix to attachments

Discussions about Forms Designer for SharePoint 2010.
Locked
User avatar
Sebastian Haugland
Posts: 43
Joined: Fri Sep 19, 2014
Contact:

04 Apr 2016

Hi

When a task has several attachment it is difficult to find the latest attachment and one of "my users" asked if I could add the upload date in front of the filename that is uploaded to the task.

I tried to change the attachment field but that did not work, any suggestions? (do I have to change the filename after saving the file?)

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

04 Apr 2016

Hi,

Your course of action would be:

1. Create a multi-line plain text field 'UploadedAttachmentsList'

2. Paste the following JS code onto the form:

Code: Select all

fd.onsubmit(function(){
	if (fd.field('Attachments').control()._el().find('tr[id^="attachRow"]').length) {
		var attachments = '';
		fd.field('Attachments').control()._el().find('tr[id^="attachRow"]').each(function(i, e){
			attachments += $(e).find('span').text().split('\\').slice(-1)[0] + '\n';
		});
		fd.field('UploadedAttachmentsList').value(fd.field('UploadedAttachmentsList').value() + attachments);
	}
	return true;
});

var attachments = fd.field('UploadedAttachmentsList').value().split('\n');
var found = false;
for (var i = attachments.length - 1; i >= 0 && !found; i --) {
	fd.field('Attachments').control()._el().find('tr span a').each(function(){
		if ($(this).text().trim() === attachments[i].trim()) {
			$(this).text('most recent ' + $(this).text());
			found = true;
			return false;
		} 
	});
} 
3. Add the UploadedAttachmentsList field onto the form and hide it with the following CSS (the style attribute):

Code: Select all

display:none; 
What all this will do is use a hidden text field to log the order of files added and add 'most recent' to the first attachment option on the list.

You can advance this piece of functionality by removing deleted files (in the onsubmit handler), adding date and time to the list.

You also need to test this feature thoroughly as it's not intended to be a complete solution, but only a guide to one.

User avatar
Sebastian Haugland
Posts: 43
Joined: Fri Sep 19, 2014
Contact:

04 Apr 2016

with "Paste the following JS code onto the form:" do you mean under Javasript? ie the red button?

or as a html field?

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

04 Apr 2016

The Javascript button at the top of Forms Designer.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests