4

Thank you for reading this. This is a bit long, but I'm trying to be as detailed as possible. Any help would be greatly appreciated. If more info is needed, please let me know. As info, I am not a (JavaScript) developer. I've been tasked to do as many things as possible OOTB.

Environment: SharePoint Online and SharePoint Designer 2013 (for workflows).

Scenario: Have a Team Site and a Subsite to it. When an item is added to a Custom List in the Subsite, the workflow is to find the matching task in the Task List on the Parent Site and mark the Task Status as “Completed”. (A variable is created in the workflow to match the item added to the list with the task.)

Success: Using the HTTP Web Service action to GET Task items via the Workflow. Evidenced by logging the response in a custom list using Create Item in List workflow action.

Issue: Using POST to add or update a Task to the task list. Continue to get the error {"error":{"code":"-1, System.Collections.Generic.KeyNotFoundException","message":{"lang":"en-US","value":"The given key was not present in the dictionary."}}}

Pre-conditions: Because we were going between site and subsite, we followed the articles to create elevated workflow permissions for use of the App Step. Did this on both the site and subsite. https://msdn.microsoft.com/en-us/library/office/jj822159.aspx, http://www.fabiangwilliams.com/2014/06/19/gotcha-on-sharepoint-designer-workflows-in-app-step/

Because this error seems to sometimes be illusive, decided to create the workflow on lists within the same Team Site to remove any possibility of authorization issue. Therefore the example shown below is not using APP Steps.

Trouble-shooting: Used Fiddler with Chrome to walk through and did not receive any errors. https://cann0nf0dder.wordpress.com/2016/09/12/getting-fiddler-to-work-with-sharepoint-online/. Viewed many, many articles also.

Workflow:

  1. Hard-coded a Variable = TempMatchString to match with a value in the Task List to bring back specific Task(s). Ignore first two lines of the workflow - will be used once the issue is resolved.

enter image description here

  1. Get Matching Task(s)

    • Build GET_RequestHeader Dictionary. Accept = application/json;odata=verbose as String and Content-Type = application/json;odata=verbose as String

    • Perform the GET HTTP Web Service request with URL: https://mycompany.sharepoint.com/HumanResourcesTS/_api/web/lists/getByTitle('ProgressReportTasks')/Items?$filter=(Title eq [%Variable:TempMatchString%]

    • Create Item in the SPListGETContent list to view the response.

    • Store the array returned in Variable “ListDataSet”. Note: I am using Get valueinstead of d/results. If I do the GET Call from the subsite I get the JSON returned with d/results as seen in most all articles online, but value when used on the parent site. I am not sure why this differs.

    • Count to number of items returned. enter image description here
  2. Get FormDigestValue

Read several articles stating need to set the X-RequestDigest to the FormDigestValue to POST.

  • Build ContextHeaders Dictionary. Accept = application/json;odata=verbose as String and Content-Type = application/json;odata=verbose as String
  • Perform the POST HTTP Web Service request with URL: https://mycompany.sharepoint.com/HumanResourcesTS/_api/contextinfo
  • Create Item in the SPListGETContent list to view the response
  • Get the FormDigestValue and store it as a Variable = digestValue enter image description here

    1. Add Task (ERROR occurs here)
  • Build ADD_Request Header dictionary. Accept = application/json;odata=verbose as String and Content-Type = application/json;odata=verbose as String and X-RequestDigest = [%Variable: digestValue%] as String
  • Build ADD_Metadata dictionary. Type = SP.Data.ProgresReportTasksListItem as String where “ProgressReportTasks” is the list name.
  • Build ADD_Parameters dictionary. __metadata = [%Variable: ADD_Metadata%] as String and Title = Created by WF on Parent Site as String
  • Perform the POST HTTP Web Service request with URL: https://mycompany.sharepoint.com/HumanResourcesTS/_api/web/lists/getByTitle('ProgressReportTasks')/Items

    Set the Properties to ensure the RequestHeaders, ResponseContent, and ResponseStatus Code were set to the correct Variables.

  • Write the responseContent to the SPListGETContent list. Get: {"error":{"code":"-1, System.Collections.Generic.KeyNotFoundException","message":{"lang":"en-US","value":"The given key was not present in the dictionary."}}}
  • Write the ResponseStatusCode to the SPListGetConent list. Get: InternalServerError enter image description here

    1. Update Task (ERROR occurs here)
  • Build POST_Request Header dictionary. All set as String. Accept = application/json;odata=verbose and Content-Type = application/json;odata=verbose and X-RequestDigest = [%Variable: digestValue%] X-HTTP-Method = MERGE (NOTE: Also tried PATCH) IF-MATCH = * Content-Length = 0
  • Build POST_Metadata dictionary. Type = SP.Data.ProgresReportTasksListItem as String where “ProgressReportTasks” is the list name.
  • Build POST_Parameters dictionary. __metadata = [%Variable: ADD_Metadata%] as String and Title = Updated by WF on Parent Site as String
  • Perform the POST HTTP Web Service request with URL: https://mycompany.sharepoint.com/HumanResourcesTS/_api/web/lists/getByTitle(‘ProgressReportTasks’) /Items(22). Hardcoded the Item ID for this first round of testing.

    Set the Properties to ensure the RequestHeaders, ResponseContent, and ResponseStatus Code were set to the correct Variables.

  • Write the responseContent to the SPListGETContent list. Get: {"error":{"code":"-1, System.Collections.Generic.KeyNotFoundException","message":{"lang":"en-US","value":"The given key was not present in the dictionary."}}}
  • Write the ResponseStatusCode to the SPListGetConent list. Get: InternalServerError InternalServerError enter image description here

Thank you!!

1
  • create dictionary item type string value : application/json;odata=verbose log every step to history to trace line by line and variables values Dec 12, 2017 at 8:05

1 Answer 1

0

One of the issues discovered what that for the metadata dictionary "type" must be with a lower case "t". I think this resolved this issue. Unfortunately, I did not answer this right away, but I remember that as an "ah ha" moment. I also used "PATCH" instead of "MERGE", but I've read arguments for both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.