Introduction
We encounter this kind of error in many different scenarios and in different programming languages as well. In this article, we will see how and when this error appears using SharePoint 2013 designer workflow and how to fix it.
Scenario
I was working on a SharePoint 2013 Designer Workflow. The workflow starts executing and somewhere in between I got the below error.
RequestorId: xxxxxxxx-xxxx-xxxx-0000-000000000000.
Details: An unhandled exception occurred during the execution of the workflow instance. Exception
details: System.FormatException: The input source is not correctly formatted. --->
System.Xml.XmlException: Encountered unexpected character 'D'. at
System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)
at System.Runtime.Serialization.Json.XmlJsonReader.Read() at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.MoveToRootNode(XmlDictionaryReader
jsonReader) at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.JXMLToJsonValue(XmlDictionaryReader
jsonReader) --- End of inner exception stack trace --- at
Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.JXMLToJsonValue(XmlDictionaryReader
jsonReader) at Microsoft.Workflow.Common.Json.JXmlToJsonValueConverter.JXMLToJsonValue(Stream
jsonStream, Byte[] jsonBytes) at Microsoft.Activities.DynamicValue.ParseJson(String json) 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)
And I found out that the error was at the Comparison statement between a Lookup field value and a String.
Now, let’s go find out how the problem arose and how to fix it.
Cause of the Error
When I say Lookup column, I have created a “Status” list to store the required statuses and I have a column “Status” which is a lookup column fetching values from the Status list as a lookup.
For demonstration I did create a workflow which looks like as shown below.
I have logged the lookup field value Status which has value “Draft”,
I have created a workflow variable statusDraft of type String and Set the workflow Variable: statusDRAFT with value “Draft”.
Then comes the comparison between the Lookup Column: Status and the Workflow Variable: statusDRAFT.
You select the Status field from Current Item -- that’s the lookup field which equals workflow variable: statusDraft.
In the below screenshot you see the variable: statusDraft returns the value as “As Dictionary from JSON” when compared directly with the lookup column
Workflow will not give any error while publishing the workflow but when you run the workflow, the Workflow gets “Suspended” with the error as shown below.
Solution
To solve this problem I have created an additional workflow variable named “statusVariable” of type “String”.
Copy the lookup field value in the workflow variable: statusVariable.
And we have the workflow variable statusDraft already with value “Draft”
Now when you compare between the Workflow Variable: statusVariable and the Workflow Variable: statusDRAFT, both the values are compared as strings. In the below screenshot you see the variable: statusDraft returns the value as “String” unlike “As Dictionary from JSON” earlier
Publish and run the workflow with the made changes, and the workflow executes perfectly without suspending as shown in the below screenshot
Summary
In this article, we saw how we get the error “input source is not correctly formatted” and how to fix it in SharePoint 2013 designer workflow.
Hope this article was helpful. Cheers!