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:
- 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.
Get Matching Task(s)
Build GET_RequestHeader Dictionary.
Accept = application/json;odata=verbose as String
andContent-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
value
instead ofd/results
. If I do the GET Call from the subsite I get the JSON returned withd/results
as seen in most all articles online, butvalue
when used on the parent site. I am not sure why this differs.- Count to number of items returned.
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
andContent-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
- Add Task (ERROR occurs here)
- Build ADD_Request Header dictionary.
Accept = application/json;odata=verbose as String
andContent-Type = application/json;odata=verbose as String
andX-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
andTitle = 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
- Update Task (ERROR occurs here)
- Build POST_Request Header dictionary. All set as String.
Accept = application/json;odata=verbose
andContent-Type = application/json;odata=verbose
andX-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
andTitle = 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
Thank you!!