Creating Word Documents from a SharePoint List Item
I got a requirement to create a word document in a library with specific content type and based on list item. The input for the document properties provided thru a list item in another SharePoint List. It means the workflow attached to a SharePoint List.
I found following articles but they are achieving thru SharePoint designer workflow and I need to achieve this using Visual Studio Declarative Workflow (SharePoint 2013 Workflow Model not WWF).
https://www.linkedin.com/pulse/creating-word-documents-from-sharepoint-list-item-juan-de-roock
https://www.netwoven.com/2015/04/24/how-to-dynamically-create-and-populate-word-document-in-a-document-library-from-custom-list/
I tried to do the same in Visual Studio but it did not worked for me and could not able to find any solution. At last I realized that SharePoint 2013 workflow executes everything using Rest API. Then I started searching for solution like how to create a word document with specific content type using Rest API. After searching hours I found following discussion blog. It helped me a lot to achieve my requirement.
https://sharepoint.stackexchange.com/questions/178220/how-do-you-create-a-new-document-in-a-sharepoint-document-library-based-on-an-ex
I called the given Rest API endpoint using HttpSend activity as below.
Method: POST
Request Headers:
Uri:
webUrl + "/_api/web/getfilebyserverrelativeurl('" + templateUrl + "')/copyto(strnewurl='" + targetItemUrl + "',boverwrite=false)"
UpdateListItem activity used to update document properties.
It worked very well for me. Hope it helps others.
I found following articles but they are achieving thru SharePoint designer workflow and I need to achieve this using Visual Studio Declarative Workflow (SharePoint 2013 Workflow Model not WWF).
https://www.linkedin.com/pulse/creating-word-documents-from-sharepoint-list-item-juan-de-roock
https://www.netwoven.com/2015/04/24/how-to-dynamically-create-and-populate-word-document-in-a-document-library-from-custom-list/
I tried to do the same in Visual Studio but it did not worked for me and could not able to find any solution. At last I realized that SharePoint 2013 workflow executes everything using Rest API. Then I started searching for solution like how to create a word document with specific content type using Rest API. After searching hours I found following discussion blog. It helped me a lot to achieve my requirement.
https://sharepoint.stackexchange.com/questions/178220/how-do-you-create-a-new-document-in-a-sharepoint-document-library-based-on-an-ex
I called the given Rest API endpoint using HttpSend activity as below.
Method: POST
Request Headers:
Uri:
webUrl + "/_api/web/getfilebyserverrelativeurl('" + templateUrl + "')/copyto(strnewurl='" + targetItemUrl + "',boverwrite=false)"
UpdateListItem activity used to update document properties.
It worked very well for me. Hope it helps others.


Comments
Post a Comment