Attachment not showing attachments on task form?


Badge +8

I've added the Attachments form control to the Task form, but when accessing a task it just shows an Add Attachment button. It does not list anything currently attached to the item. Am I doing something wrong here? Do I need to use a different control or a workaround to get current attachments to show on the Task form?


10 replies

Badge +7

Hi,

Follow those steps for Vadim Tabakman‌.

Nintex Workflow - Get Attachment Urls UDA - Vadim Tabakman 

BR,

Philip

Userlevel 6
Badge +13

This is because a task is a separate list item to the list item your attachment belongs to. Under the Workflow Tasks list, you will find your task and this illustrates it's a completely independent item in a different list.

If you wanted to just provide a link to the attachment I think you can add a calculated value and use the Attachments property under Item properties to retrieve the URL.

I haven't tested this, but give it a try and report back.

Badge +8

I wish. Unfortunately, all it returns is:

it seems really weird you have to build something custom to link to attachments from the item on the task item. 

Badge +8

I'll give it a look. It seems really weird you have to build something custom to link to attachments from the item on the task item. 

Userlevel 6
Badge +13

alternative is to use the Hyperlink control in View Mode and build the url yourself. 

The url will be "https://domain/sites/sitename/lists/listname/attachments/ID/attachmentname.doc

all the bold elements are obviously to be replaced by you, the ID is the list ID of the item that the attachment is associated with and then obviously the attachment name and extension. You could build this as a variable in your workflow and then reference the variable in your hyperlink field.

Badge +8

I'm liking this idea, but how would I gather the attachment name.extension into a variable? Especially in the case of multiple attachments?

I thought maybe I do a collection and set the value to a List Lookup for the Current Item field Attachments. When I do that, and then log to history I still only get the "True"message. 

Userlevel 6
Badge +13

Sorry, should have detailed that.

Turning Attachments into working documents - Part Deux 

In this blog I've written we query the formData XML using the Query XML action. This allows us to store the filenames in a collection as you require.

Have a read through and let me know if you need anything explained further for you, but hopefully it should make sense which bits of the blog you need to use and adapt.

‌ attachments

Badge +8

So I figured, instead of doing all this, I'm just going to use a Rich Text field and link back to the original form. This is just way too much of a workaround to do something as simple as displaying attachments from the form. I love everything about Nintex Forms and Workflows so far but this seems like something Nintex would have implemented/fixed a long time ago.

Badge +5

Hi NJ,

Could you please explain your solution for displaying attachments using the rich text field?

Thanks

Badge +8

It's not a rich text field, but this is what I did in the end.

On your task form you'll need three controls. Two calculated values, and one Panel. 

One CV has a formula of "List Name" and JS variable of "calcListName". The other CV has a formula of "ID"(Item ID) and a variable name of "calcListItemId". 

Below is the JS that you add to the task form. If you know JS you should be able to modify the below to get what you need. Comment out anything regarding Service URL. That's a completely unrelated function.

var serviceUrl;
var siteUrl;
   
NWF$().ready(function () { 
serviceUrl = 'http://IGNORE/THIS/';
});NWF.FormFiller.Events.RegisterAfterReady(function () {
var siteUrl = _spPageContextInfo.webAbsoluteUrl;

//Note, list title and ID are calculated fields on the review form.
var listTitle = NWF$('#' + calcListName).val();
var listItemId = NWF$('#' + calcListItemId).val();

//Build the url to the current list item's attachments.
var attachmentsUrl = siteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items(" +
  listItemId + ")/AttachmentFiles"; NWF$.ajax({
  url: attachmentsUrl,
  type: "GET",
  headers: { "Accept": "application/json; odata=verbose" }
})
.done(function(data) {
  if (data) {
   //Check for any attachments, and hide the container if no attachments exist.
   if (data.d.results.length === 0) {
    NWF$('.AttachmentsContainer').hide();
   } else {
    //Get a reference to the attachmens panel.
    var attachmentsPnl = NWF$('.ItemAttachments');
   
    //Add an opening div tag.
    var attachmentsHtml = '<div>';
   
    //Iterate through the returned list of attachments, inserting a link.
    NWF$.each(data.d.results, function() {
     //Add an opening div tag.
     attachmentsHtml += '<div>';
   
     //Get the file name and path.
     var fileName = this.ServerRelativeUrl.substr(this.ServerRelativeUrl.lastIndexOf('/')+1);
     var filePath = this.ServerRelativeUrl;
    
     //Append the html.
     attachmentsHtml += "<a href='" + filePath + "' target='_blank'>" + fileName + "</a>";
    
     //Close the div tag.
     attachmentsHtml += '</div>';
    });
   
    //Close the div tag, and set the panel's html.
    attachmentsHtml += '</div>';
    attachmentsPnl.html(attachmentsHtml);
   }
  } else {
   //Hide the attachments panel.
   NWF$('.AttachmentsContainer').hide();
  }
})
.error(function(jqXHR, textStatus, errorThrown) {
  alert(jqXHR.responseText || textStatus);
});
});function btnValidate_Click() {
var errMsg = '';

Reply