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...
- Inside a component workflow, First do a POST webrequest call on {Variable:Current Site URL}/_api/contextinfo to retrieve the FormDigest.
- 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
- 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') - 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
You retrieved the {FormDigest} from the initial call. - 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-permissions-by-using-the-sharepoint-workflo
- You have now given the correct rights to your app... and now it should run properly.
- 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!