Add date as prefix to attachments

rss

Posted by frodo1967 - Apr 4 ’16 at 02:22

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?)

 

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 3 days
    #1 by rostislav Apr 4 ’16 at 06:55

    The message was removed by a forum moderator.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 3 days
    #2 by rostislav Apr 4 ’16 at 06:58

    [#1]:

    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:

    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):

    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.

  • frodo1967
    Member
    Member for: 5 years 2 months 20 days
    #3 by frodo1967 Apr 4 ’16 at 08:25

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

    or as a html field?

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 3 days
    #4 by rostislav Apr 4 ’16 at 09:15

    [#3]: The Javascript button at the top of Forms Designer.

Displaying 1 to 4 of 4 messages