cancel
Showing results for 
Search instead for 
Did you mean: 
alexjolynintex
Nintex Newbie

Copy task attachments to Master Item on O365...

Jump to solution

Hi all,

 

just to give you the context, my company is working on a 300 workflows tenant splitted into a lot of site collections.

We have built a component workflows called "Copy TaskAttachments to Master Item" that copies the task attachments to the underlying item. It also update the NFFormData field to put the attachment not only in the "default" attachment components, but exactly where the attachment should be in the form (this part is not detailled in the post).

 

It works 95% of the time ! I'm here for the 5 last %

 

First, a few tips, if you want to do it too...

  1. Inside a component workflow, First do a POST webrequest call on {Variable:Current Site URL}‌/_api/contextinfo to retrieve the FormDigest.
  2. Retrieve names and URL of your task attachments using another GET webservice call on "{Variable:Current Site URL}‌/_api/Web/lists/getbytitle('‎‏{Variable:Workflow Tasks List Name}‌')/items(‎‏{Variable:Task Item ID}‌)/AttachmentFiles
    2019-02-16_14-31-24.png

     

    Retrieve URLS and files and store them in some collections...
  3. Create and delete a Dummy file (just to ensure that the "Attachment" folder is created using another webservice call  on
    ‎‏{Variable:Current Site URL}‌/_api/web/lists/GetByTitle('‎‏{Variable:List Name}‌')/items(‎‏{Variable:List Item ID}‌)/AttachmentFiles/add(FileName='dummy.txt')
  4. Then loop on those collections and call the POST HTTPService
    ‎‏{Variable:Current Site URL}‌/_api/web/getfilebyserverrelativeurl('‎‏{Variable:Attachment URL}‌')/copyto(strnewurl='‎‏{Variable:List Relative URL}‌/Attachments/‎‏{Variable:List Item ID}‌/‎‏{Variable:Attachment File Name}‌',bOverWrite=true)
    and for that use the following header
    2019-02-16_14-37-11.png
    You retrieved the {FormDigest} from the initial call.
  5. Package it...test it... it fails if you run it on another site/sitecoll with the status code "Forbidden" on the CopyTo service call ! Basically, your remote workflow app doesn't have the correct access on the local site. To solve this problem, follow the link :  https://docs.microsoft.com/en-us/sharepoint/dev/general-development/create-a-workflow-with-elevated-...
  6. You have now given the correct rights to your app... and now it should run properly.
  7. Here is my problem now...

    It runs most of the time, and for a few cases , the copyto Webservice call gives us an "Unauthorized" status code without explanation.

... we have been investigating for weeks now, and I have no clue on the solution!

We tried the following :

  • The formdigest is maybe wrong,but why then it would work on all the hundreds of other workflows?
  • The permissions have been updated on the site : Can't be...I have tried with my own admin account, same behavior.
  • We checked and the "workflow can use app permissions" feature is activated everywhere.

any idea would be appreciated!

thanks!

Labels: (1)
0 Kudos
Reply
8 Replies
Nintex Employee
Nintex Employee

Re: Copy task attachments to Master Item on O365...

Jump to solution
Hi Alex,

You mention a that this fails in a few cases, is it the same workflow/users/site where this fails, or is it randomly failing (e.g. same user runs the same workflow 20 times and one time it fails).

Thanks,

Callum
0 Kudos
Reply
alexjolynintex
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution
Hi Callum,
sadly not! Any user running some of those workflows are having the issue. Even me with my site coll admin account.
So, I wouldn't try to investigate on the user.


0 Kudos
Reply
allan
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution

This was a tricky one, but I think I solved your issue!

The issue is because the REST call is limited to 400 characters, so when setting the URL, the variables are replaced and you can have a really long URL.
Just imagine doing this on a subsite ("/sites/MyProjectSite1/MyProjectSite11/MyProjectSite111"), add the length of the list name and the name of the file ("maybe_you_have_a_really_long_file_name.pdf"), it can become huge quite quickly.

The trick is to use REST query with parameters.
Instead of :

{Variable:Current Site URL}‌/_api/web/getfilebyserverrelativeurl('‎‏{Variable:Attachment URL}‌')/copyto(strnewurl='‎‏{Variable:List Relative URL}‌/Attachments/‎‏{Variable:List Item ID}‌/‎‏{Variable:Attachment File Name}‌',bOverWrite=true)

Use:

{Variable:Current Site URL}‌/_api/web/getfilebyserverrelativeurl(@v0)/copyto(strnewurl=@v1,boverwrite=true)?@v0='‎‏{Variable:AttachmentURL}‌'&@v1='‎‏{Variable:List Relative URL}‌/Attachments/‎‏{Variable:List Item ID}‌/{Variable:Attachment File Name}‌'

The parameters (@v0 and @v1) are not counted in the the length of the request, only what's before the "?". That's because it is not replaced at runtime by Nintex, but is interpreted by the SharePoint API, it accepts long URLs, but not long function calls.
This did the trick for me.

View solution in original post

Reply
alexjolynintex
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution
mate, how could I do without you ?
Smiley Wink
0 Kudos
Reply
Jacobliam
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution

There are so many online assignment help website to help you. It is important to choose the best one among the many. Before choosing the one go for that website reviews first and then check the website like their services, prices, discounts, website interface, and everything. Go through their samples that how they write so, you can understand the level of their experts.

0 Kudos
Reply
DomenicTylor
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution

Australiaassignmenthelp.com is provide proofreading services Australia assignment work in our web portal. We have done many projects of assignment work and students can check sample papers than hire our experts. We provide all type of writing services.

0 Kudos
Reply
tharsanceymplon
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution

Thank you for your answer blog. I have done the feature. Really Great.

Reply
totalassignment
Nintex Newbie

Re: Copy task attachments to Master Item on O365...

Jump to solution

Our management assignment help is what various students aspire for. We are leading others in this term of timely delivery and affordable rates.

0 Kudos
Reply