SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

September, 2014

  • How to create a folder in document library or a list item in a list utilizing REST API in SharePoint 2013 workflows

    This post is a contribution from Kevin Jacob Kurian, an engineer with the SharePoint Developer Support team

    We come across this requirement wherein we would need to utilize REST API calls in SharePoint 2013 workflows. Using the new “Call HTTP web-service action” in SharePoint 2013, we can achieve the same. We could utilized any of the available REST APIs to meet our requirement but in this example, I will show how to create a folder (in a document library) and a list item (in a list) using REST API.

    1. I created a Site workflow (even a List workflow should work out)

    2. The first Dictionary is the header (Output variable) with the following key/value pairs.

    3. Then I created the second Dictionary which is metadata (Output Variable). The SP.Folder type specifies that we are creating a SPFolder utilizing the REST call.

    4. The last Dictionary is the parameters (Output variable)

    5. The above Server Relative URL gives the relative URL for the document library (“Shared Documents”) along with the new folder name (“Test 2”). In this example, I am creating the folder in a sub-site (“sub”) which requires setting up Workflow elevated privileges shown in Steps 10-13. If we are creating the folder in the same site, then we can avoid setting up the Workflow elevated privileges and by Step 9, our workflow setup is complete.

    6. Then we add the Call HTTP web-service with the following details.

    7. The REST API call should contain the name of the sub-site, “sub”.

    8. Set the RequestHeaders to Variable header.

    9. Also set the Request parameters to variable:Parameters.

    10. Now we need to set the workflow to run in elevated privileges.

    11. Please follow this walk-through blog to set the Workflow elevated privileges, http://msdn.microsoft.com/en-us/library/jj822159.aspx

    12. The only place where we will differ is the Permissions Request

    <AppPermissionRequests>

    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />

    </AppPermissionRequests>

    13. Don’t change the above Scope value and keep it the same.

    14. The above scopes gives workflow with App Steps privileges at a site-collection level.

    15. Once the above steps are completed, our workflow should work fine and we should be able to create the folder in sub-site.

    Add-On

    a) For creating a list item using the same approach, we need some slight changes.

    b) In Step 3 (above), the type of the list item should be specified like:-

    c) The type of the List item varies from each list in the site and to get the type value for your list, you would need to browse to this REST url (http://<site-name>/_api/web/lists/getbytitle(‘<listname>’)/items) and get the <category> tag’s term attribute. The below snippet shows my example SPList type:-

    d) In Step 4 (above), instead of the ‘ServerRelativeURL’, we would need to specify the list fields and list field values. Since I am targeting a simple list, I just have a ‘Title’ field. The below entries should replace the ‘ServerRelativeURL’.

    e) In Step 6 (above), we would need to utilize this particular REST API call:-

    f) The remaining steps would be the same for the create folder workflow.

    Hope this helps in understanding how REST API calls happen from a SharePoint 2013 workflow.

  • Visual Studio 2013 Workflow: Failed to translate expression because of the following error: Translating the method or one of its overloads to an activity is not supported

    This post is a contribution from Charls Tom, an engineer with the SharePoint Developer Support team

    When you build a Visual Studio Workflow targeting SharePoint 2013, you will see this error if you are using any expression that’s not supported inside a workflow.

    clip_image002

    The reason for this is that 2013 workflows support only a very limited subset of .NET framework methods. In case you really need to so some operations that are not supported, best workaround is to implement it as a custom REST service method and call it using (HttpSend) where necessary.

    Hope this helps!

  • SharePoint Designer 2013: Unexpected Error on server associating the workflow

    This post is a contribution from Raghavendra Nanjaiah, an engineer with the SharePoint Developer Support team

    What is the issue?

    When you try to publish the SharePoint 2010 reusable or list workflow on SharePoint 2013 platform using SharePoint designer 2013 you will get following exception in UI

    clip_image002

    If you carefully observe the ULS logs

    08/22/2014 16:17:53.40          w3wp.exe (0x2610)      0x05D4            SharePoint Foundation      Legacy Workflow Infrastructure           xmfh    Medium           Workflow Compile Failed: Could not find a part of the path 'C:\Users\devapppool\AppData\Local\Temp\cjjkiult.tmp'. b118b19c-3fad-30ad-ac8b-ed8c02395742

    Why we face this issue?

    During the workflow publishing phase, SharePoint will create couple of temporary files under the temp folder (of the app pool service account). As part of clean-up process w3wp process will delete this files later.

    Sometimes, instead of deleting content inside temp folder w3wp process deletes the temp folder. Because of which workflow publishing fails with “Could not find a part of the path”

    How to work around this issue?

    Create a text file and provide read only access to file. This will stop process from deleting temp folder.

    1. Navigate to C:\Users\<service-acct>\AppData\Local\Temp on both the server (WFE1 and WFE2)

    2. Create a text file inside the temp folder and in the properties check read-only option.

    3. Reset iis /noforce

    4. Publish the workflow.