I am using the "copy item" and "convert document" actions to copy/generate document in a sharepoint document library.
I would like to know how I can fetch the ID of the copied/generated document?
I have tried to get the last modified item in the target list but I have an issue when I have several workflows in parallel: sometimes there is a mix up in documents.
Thanks in advance for your help
Solved! Go to Solution.
Looks like copy item does not output a result.
The 'Copy to Sharepoint' action outputs the URL of the destination and for the 'Convert Document' action I would use a build string action to set the variable for the destination URL.
As you know the destination URL, use a 'Query List' action.
Point it at the destination list then filter items based on 'encoded absolute URL' field and the variable for destination/output URL from above.
You can then output the ID of the item into a variable.
Thanks a lot for your help but I have the following issue:
- 'Copy to Sharepoint' seems to be able to copy a document on which the workflow is currently running. It is not able to copy an item from another library (for particular reasons, my workflow is running on a list item from which I get the document ID I want to copy from a source DocLib to a target DocLib). Sorry, I forgot to mention that detail in my initial post
I have tried to create a UDA following the example provided here: How to copy items using Nintex Workflow | YBBEST SharePoint Pie but the same problem as before: it seems that I cannot use 'QueryList' with 'Encode Path Url' to retrieve the item.
I don't if there is another attribute I could use to retreive the document
Thanks for your help
Ok I've had another crack at this.
Assuming source and destination in the same subsite.
I've created a template which you can import to take a look.
Basically a workflow on a custom list.
' Documents' library for source documents.
'Site Assets' for destination. (You will need to modify the variable for the URL to the target library.
Knowing that, I'm using a query action to find the filename(name) of the source document plus other variables, eg URL.
Copy item action as one example then a query to grab the ID of the destination doc that was copied.
The next uses a regular expression to create a pdf filename
Then build a string for the destination
Then a convert document action to convert to pdf.
Then a query action to find the ID of the converted document.
Hope this is closer to what you are after?
Thanks for your valuable input.
It works but except in 1 case: if document already exists in target DocLib, Sharepoint will create a new document with timestamp added in the filename. Well, this is an option of the Copy Item for sure but if you have any idea to manage this case, I would appreciate.
I just pulled up my site to do a check on the actions.
If you just want to add version
1) For the copy item action you could tick the box overwrite item then configure major versions on the destination library.
2) for the convert document action, there is a drop down of overwrite or create new version. Again you would need to change the version settings on the library.
If you need to ensure uniqueness before it is created.
Change the build string actions to create a unique destination file name before the file is copied / converted.
(eg build the string with a date/timestamp, etc)
As you still know what the destination filename will be you can still query the destination library for the destination document.
Yes this is a pain isn't it, the Create Item action returns an ID, but not Copy Item.
I have worked around this in my workflows by copying the item then-
This works ok for low-frequency actions, however it would be prone to race condition issues if the same user ID is going to be running multiple instances of the same workflow concurrently. Then you would need to use a "copy key" type arrangement, to put a unique key onto the copied item (maybe the running workflow ID) so you can find it uniquely.
I discussed on a previous post to use a variable to create the destination file name and URL for the copy item action.
Rather than query the destination list for your reverse date order of items created by me, query by the name of the item as that is known as a variable.
That will give you the 100% uniqueness and avoid your race conditions.
There is a nwf template attached above you can import and take a look if you are keen.
I realize this is an old thread, but I'm having the same problem and the proposed solution here doesn't quite work for me. I am using the Convert Document action and I know the URL of the destination document. However, I can't use the Query list action because my list name is variable. I have the library name in a variable, but I can't use that in the Query action.
I tried using the Call web service action with the _vti_bin/lists.asmx and the Web request action with _api/lists REST calls, but I haven't found the right combination to retrieve the ID of the new document.
Do you have any suggestions for this scenario?