Levy
Scout

Adding Item Attachments with SP.RequestExecutor in a Nintex 365 Task Form

Jump to solution

In a Workflow we have some Tasks Forms where the users should have the ability to view attachments from the related list item and also add new files or delete a selected file when approving the task.

We have added a panel to the Task Form and render the related Attachments as also a input of type file into that panel.

This is working fine.

pic.png

 

But the code to add a new file or delete a file does not work. 

We get 405 Method not Allowed.

We use following code with type:POST to add a file:

context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
var executor = new SP.RequestExecutor(appweburl);
var fullUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listName + "')/items("+ID+")/AttachmentFiles/add(FileName='" + file.name + "')?@target='" + encodeURIComponent(hostweburl) + "'";
executor.executeAsync({
    url: fullUrl,
    type: "POST",
    processData: false,
    contentType: "application/json;odata=verbose",
    data: buffer,
    headers: {
	"accept": "application/json;odata=verbose"
    },
    success: function (data) {
        //
    },
    error: function (err) {
        //
    }
});

The code resists in a js file in the SiteAssets library and is referenced in the task form.

As we understood, we do not need to determine the request digest as the SP.RequestExecutor is taking care of it.

 

From the console we grab the request url which has been send:

We replaced our domain name with xxx here.

 

https://xxx-ddcd64337d0669.sharepoint.com/sites/sponsoring/FormsApp/_api/SP.AppContextSite(@target)/...

 

This looks good to us.

The user running the Workflow and the user participating are having appropriate permissions

What are we missing?

 

 

Labels: (1)
0 Kudos
Reply
1 Reply
Levy
Scout

Re: Adding Item Attachments with SP.RequestExecutor in a Nintex 365 Task Form

Jump to solution

I used another approach now because even Nintex wasn't able to help. They do not support custom javascript when opening a case (which I did).

 

Now I still have the panel to show attachments from the related list item.

Additionally I have added the Attachment-control from the task list to the task-form.

Users can now add new attachments (to the task).

I have created a Nintex Workflow Cloud Component Workflow which will copy the attachments from the task list item to the related list item. This workflow will also delete the attachments from the task list.

NWC CW.png

 

I have some Variables, so that I can reuse this Component Workflow:

 

NWC CW Variables.png

 

The siteurl is the url to the site where the list and the task list resists.

All other variables are self explained.

 

To delete the attachments from the task, I declared the web service call liks so:

 

NWC CW Delete.png

I hope this might help others...

Cheers, Ronny

0 Kudos
Reply