Check out, Check in + Workflow 2013

SharePoint Designer 2013 workflows have gained a lot of functionality from the ability to make web service calls. Many of the Actions that are not available out of the box can be reproduced by using SharePoint’s REST API.

One example is a reusable workflow that can checkout and check-in files according to where the workflow is running.

The “Check Out Item” activity does not let you choose a Workflow Variable and thus has to target a fixed list. While this works fine for a list workflow, when you try to make a reusable workflow this can be a hindrance.


 

To overcome this limitation we can leverage the REST API to execute the Check out and Check in steps of the workflow.

We will use the “Call HTTP Web Service” activity


 

We will use the following URL:

[%Workflow Context:Current Site URL%]/_api/web/Lists(guid'[%Workflow Context:List ID%]’)/getItemById([%Current Item:ID%])/File/CheckOut()

Detailing the variables used in the URL we have:

[%Workflow Context:Current Site URL%] – Contains the value of the Site where the workflow is running

/_api/web/Lists(guid'[%Workflow Context:List ID%]’) – Path to the list where the workflow is associated

/getItemById([%Current Item:ID%]) – Gets the Item where the workflow is running

/File/ – Access the File linked to the Document Library

/CheckOut() – Executes the Check out action

We need to pass a little more information to the activity along with the URL

Insert a “Build Dictionary” before the “Call HTTP Web Service” activity


And insert the “Accept” and “Content-Type” keys, both with the “application/json;odata=verbose” values


 

After building the dictionary you need to link it to the “Call HTTP Web Service” activity by right clicking the activity and choosing “Properties…”


Link your new dictionary to the RequestHeaders parameter of the activity.

The RequestType parameter depends on the action that will be executed, in this case, POST.

The other parameters are not necessary in this case.


 

The variable assigned to the ResponseStatusCode parameter is used to check if the action was properly executed and the ResponseContent dictionary can be used to read information sent by the Web Service (in this case, nothing).

After executing the Check out, the workflow is free to make changes to the items. Just do not forget to check in the changes by replicating the previous steps but using the Check in operation instead.

/File/CheckIn(comment=’Check in comment’, checkintype=0)