How to get JSON item in web service workflow?


Im tried to get json item in workflow,But was unable to obtain "RtnCode",how to do it?


This my JSON,

{
    "MerchantID": "1032017",
    "RtnCode": "2",
    "RtnMsg": "Get Succeeded",
}

My workflow :

Get RtnCodefrom Variable: DealItems

Error code:

RequestorId: f85b0795-6682-fde7-0000-000000000000.

Details: An unhandled exception occurred during the execution of the workflow instance.

Exception details: System.InvalidOperationException: Looking up a value using a key is not supported on an instance of 'Microsoft.Activities.Dynamic.DynamicPrimitive'. at Microsoft.Activities.Dynamic.DynamicItem.TryGetValue(String key, DynamicItem& value) at Microsoft.Activities.Dynamic.DynamicValueBuilder.PathSegmentFactory.ObjectPathSegment.Get(DynamicItem obj) at Microsoft.Activities.GetDynamicValueProperty`1.Execute(CodeActivityContext context) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity GetDynamicValueProperty<String> Start Sequence Flowchart Sequence Pay.WorkflowXaml_07f732da_c82a_4234_abd5_34c32c637413

February 11th, 2015 5:35am

Hi Felaray,

Are you calling http web service to access JSON data in dictionary in SharePoint 2013 Workflows using SharePoint Designer 2013 ?

If so, you need to find the path of the "RtnCode" in the JSON data. You can refer to the Get item from Dictionary action as below:

Get d/results(0)/RtnCode form xx (Output to xx)

More information:

Working with Web Services in SharePoint 2013 Workflows using SharePoint Designer 2013

Calling the SharePoint 2013 Rest API from a SharePoint Designer Workflow

Reference:

https://social.technet.microsoft.com/Forums/en-US/a10c5e7e-cefc-47bb-9ec5-14abfd8dc922/call-http-web-service-workflow-action-access-json-data-in-dictionary?forum=sharepointdevelopment

Thanks,

Eric

Forum Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 7:46am

Hi Eric. This ismy full JSON,no more path.

{
"MerchantID": "1032017",
"RtnCode": "2",
"RtnMsg": "Get Succeeded",
}

I found the problem is that web service return "text/html" format to me , if use "application/ json"is work.But I can not change the source header.

How to get elements when
"text/html" ?

thanks!

February 12th, 2015 8:05am

Hi Felaray,

I have a similar issue and what I tried to do is to install JSON.NET in my project and used the "Assign" activity (under "Primitives" category on the toolbox) to assign the string to an object:

Newtonsoft

.Json.JsonConvert.DeserializeObject(resultFromCustomActivity)

but unfortunately did not work. I am getting this exception:

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

If you cannot really change the source header, you might need to create a code custom activity and pass in your string and use JSON.NET, parse it and return what you want.

Another "easier" option might involve doing some nasty parsing (using the Assign Activity) by finding the index of your "RntCode:" and getting the next set of characters before the comma. Since the .NET classes to utilize are limited it would be worth trying to use a RegEx

resultFromCustomActivity

.Substring(0, 10)


  • Proposed as answer by RicardoAleG 10 hours 49 minutes ago
  • Unproposed as answer by RicardoAleG 10 hours 45 minutes ago
  • Edited by RicardoAleG 10 hours 38 minutes ago adding more comments
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2015 4:46pm

Hi Felaray,

I have a similar issue and what I tried to do is to install JSON.NET in my project and used the "Assign" activity (under "Primitives" category on the toolbox) to assign the string to an object:

Newtonsoft

.Json.JsonConvert.DeserializeObject(resultFromCustomActivity)

but unfortunately did not work. I am getting this exception:

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

If you cannot really change the source header, you might need to create a code custom activity and pass in your string and use JSON.NET, parse it and return what you want.

Another "easier" option might involve doing some nasty parsing (using the Assign Activity) by finding the index of your "RntCode:" and getting the next set of characters before the comma. Since the .NET classes to utilize are limited it would be worth trying to use a RegEx

resultFromCustomActivity

.Substring(0, 10)


  • Proposed as answer by RicardoAleG Friday, April 10, 2015 8:46 PM
  • Unproposed as answer by RicardoAleG Friday, April 10, 2015 8:49 PM
  • Edited by RicardoAleG Friday, April 10, 2015 8:56 PM adding more comments
April 10th, 2015 8:44pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics